public ServiceResult InsertRawMaterialForm(Raw_Material_Form pForm) { try { using (var db = new AgnosDBContext()) { db.Raw_Material_Form.Add(pForm); db.SaveChanges(); db.Entry(pForm).GetDatabaseValues(); return(new ServiceResult() { Code = ReturnCode.SUCCESS, Msg = Success.GetMessage(ReturnCode.SUCCESS_INSERT), Field = Resource.Income_Raw_Material }); } } catch (Exception ex) { return(new ServiceResult() { Code = ReturnCode.ERROR_INSERT, Msg = Error.GetMessage(ReturnCode.ERROR_INSERT), Field = Resource.Income_Raw_Material, Exception = ex }); } }
public ServiceResult UpdateRawMaterial(Raw_Material pRaw, Raw_Material_Form pPendingform = null, Raw_Material_Form pRejform = null, Raw_Material_Form pPassform = null) { try { using (var db = new AgnosDBContext()) { var current = db.Raw_Material.Include(w => w.Raw_Material_Attachment).Where(w => w.Raw_Material_ID == pRaw.Raw_Material_ID).FirstOrDefault(); if (current != null) { if (pPendingform != null) { var form = db.Raw_Material_Form.Where(w => w.Raw_Material_ID == current.Raw_Material_ID && w.Status == Material_Status.Pending).FirstOrDefault(); if (form != null) { db.Raw_Material_Form.Remove(form); } db.Raw_Material_Form.Add(pPendingform); } if (pRejform != null) { var form = db.Raw_Material_Form.Where(w => w.Raw_Material_ID == current.Raw_Material_ID && w.Status == Material_Status.Reject).FirstOrDefault(); if (form != null) { db.Raw_Material_Form.Remove(form); } db.Raw_Material_Form.Add(pRejform); } if (pPassform != null) { var form = db.Raw_Material_Form.Where(w => w.Raw_Material_ID == current.Raw_Material_ID && w.Status == Material_Status.Passed).FirstOrDefault(); if (form != null) { db.Raw_Material_Form.Remove(form); } db.Raw_Material_Form.Add(pPassform); } SaveProductMaping(db, pRaw.Product_Code, pRaw.Product_Name); pRaw.Update_By = userlogin.Email_Address; pRaw.Update_On = currentdate; pRaw.Record_By = userlogin.Profile_ID; db.Entry(current).CurrentValues.SetValues(pRaw); db.SaveChanges(); } return(new ServiceResult() { Code = ReturnCode.SUCCESS, Msg = Success.GetMessage(ReturnCode.SUCCESS_UPDATE), Field = Resource.Income_Raw_Material }); } } catch (Exception ex) { return(new ServiceResult() { Code = ReturnCode.ERROR_UPDATE, Msg = Error.GetMessage(ReturnCode.ERROR_UPDATE), Field = Resource.Income_Raw_Material, Exception = ex }); } }