public int SaveClientEmployee(ClientEmployeeModel model, bool updateRecord = true) { StrankaZaposleni_PDO strZap = new StrankaZaposleni_PDO(); try { strZap.StrankaOsebeID = model.idStrankaOsebe; strZap.StrankaID = model.idStranka; strZap.OsebeID = model.idOsebe; if (strZap.StrankaOsebeID == 0) { strZap.ts = DateTime.Now; strZap.tsIDOsebe = model.tsIDOsebe; context.StrankaZaposleni_PDO.Add(strZap); context.SaveChanges(); } else { if (updateRecord) { StrankaZaposleni_PDO original = context.StrankaZaposleni_PDO.Where(sz => sz.StrankaOsebeID == strZap.StrankaOsebeID).FirstOrDefault(); context.Entry(original).CurrentValues.SetValues(strZap); context.SaveChanges(); } } return(strZap.StrankaOsebeID); } catch (Exception ex) { throw new Exception(ValidationExceptionError.res_08, ex); } }
public IHttpActionResult GetClientEmployee(int empId) { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { /* Get employee having Id as empId from database */ var Employee = (from emp in db.ClientEmployees where emp.Id == empId select emp).FirstOrDefault(); var clientEmp = new ClientEmployeeModel(); clientEmp.Client_Id = Employee.Client_Id; clientEmp.client = Employee.Client.ShortName; clientEmp.FirstName = Employee.FirstName; clientEmp.LastName = Employee.LastName; clientEmp.MiddleName = Employee.MiddleName; clientEmp.PhoneNumber = Employee.PrimaryPhone; clientEmp.SecondaryNumber = Employee.SecondaryPhone; clientEmp.Email = Employee.Email; clientEmp.Fax = Employee.Fax; clientEmp.Department = Employee.Department; clientEmp.ImageOne = Employee.ImageOne; clientEmp.ImageTwo = Employee.ImageTwo; /* return an object of clientEmployee */ return(Content(HttpStatusCode.OK, new { clientEmp })); } } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.InternalServerError, "An error occured, please try again later")); } }
public WebResponseContentModel <ClientEmployeeModel> SaveClientEmployeeChanges(ClientEmployeeModel newData) { WebResponseContentModel <ClientEmployeeModel> model = new WebResponseContentModel <ClientEmployeeModel>(); try { model.Content = newData; model = PostWebRequestData <WebResponseContentModel <ClientEmployeeModel> >(WebServiceHelper.SaveClientEmployeeChanges(), "post", model); } catch (Exception ex) { model.ValidationErrorAppSide = ConcatenateExceptionMessage(ex); } return(model); }