public ActionResult SaveStaff(StaffManagementViewModel model)
{
ASPNETMASTERPOSTEntities db = new ASPNETMASTERPOSTEntities();
//string result = "Error Staff Info is not saved!";
var result = false;
try
{
tblCompany comp = new tblCompany();
if (model.tblCompany.CompanyId > 0)
{
comp = db.tblCompanies.Where(a => a.CompanyId == model.tblCompany.CompanyId).FirstOrDefault();
}
{
comp.DateJoin = model.tblCompany.DateJoin;
comp.Department = model.tblCompany.Department;
comp.JobTitle = model.tblCompany.JobTitle;
if (model.tblCompany.CompanyId <= 0)
db.tblCompanies.Add(comp);
db.SaveChanges();
model.CompanyId = comp.CompanyId;
}
tblStaff staff = new tblStaff();
if (model.StaffId > 0)
{
staff = db.tblStaffs.Where(a => a.StaffId == model.StaffId).FirstOrDefault();
}
staff.StaffNo = model.StaffNo;
staff.Picture =Picture ;
staff.FName = model.FName;
staff.LName = model.LName;
staff.BirthDate = model.BirthDate;
staff.PhoneNo = model.PhoneNo;
staff.Email = model.Email;
staff.FirstName = model.FirstName;
staff.LastName = model.LastName;
staff.PhoneNumb = model.PhoneNumb;
staff.CompanyId = model.CompanyId;
if (model.StaffId <= 0)
{
db.tblStaffs.Add(staff);
}
db.SaveChanges();
result = true;
}
catch (Exception ex)
{
throw ex;
}
return Json(result, JsonRequestBehavior.AllowGet);
}
Vishal JoshiPosted Jan 23, 2024, 10:34 AM
Hello Emmanuel,
Either saving image to the database you can upload image to the server and save the relative path.
whenever require you can return relative path and it will show the image on the page.
Code Sample
Upload image to the server
use the path to save to the database along with other data like name, type etc,
Thanks
Vishal
Anandu G NathPosted Jan 25, 2024, 12:58 PM
Emmmanuel FIADUFEPosted Jan 24, 2024, 11:42 AM
Thank you team for your support
Sachin SinghPosted Jan 19, 2024, 4:32 PM
In the given code, i can't see where have you defined the picture variable.
Is it a byte[] or it is a string "image path"?
your complete code should be like this, where i am assuming that you are sending the picture as byte[] to controller and byte[] picture is defined as a property in your "StaffManagementViewModel" model