public GencodeDayDTO Save(GencodeDayDTO dto) { try { using (SEDESOLEntities db = new SEDESOLEntities()) { GEN_CODE_DAY day = db.GEN_CODE_DAY.FirstOrDefault(v => v.Id == dto.Id); if (day != null) { GEN_CODE_DAY day2 = db.GEN_CODE_DAY.FirstOrDefault(v => v.Id_Year == dto.Id_Year && v.Id_Month == dto.Id_Month && v.Id != dto.Id); if (day2 != null) { dto.Message = "Se ha ingresado previamente una fecha para el mes y año seleccionados."; } else { day.Id_Month = dto.Id_Month; day.Id_Year = dto.Id_Year; day.Day = dto.Day; if (db.SaveChanges() > 0) { dto.Id = day.Id; dto.Message = "SUCCESS"; } } } else { GEN_CODE_DAY day2 = db.GEN_CODE_DAY.FirstOrDefault(v => v.Id_Year == dto.Id_Year && v.Id_Month == dto.Id_Month); if (day2 != null) { dto.Message = "Se ha ingresado previamente una fecha para el mes y año seleccionados."; } else { day = new GEN_CODE_DAY(); day.Id_Month = dto.Id_Month; day.Id_Year = dto.Id_Year; day.Day = dto.Day; db.GEN_CODE_DAY.Add(day); if (db.SaveChanges() > 0) { dto.Id = day.Id; dto.Message = "SUCCESS"; } } } return(dto); } } catch (Exception ex) { return(new GencodeDayDTO()); } }
public string Save(CaptureApprovalDTO dto, int approveStatus, int level) { using (SEDESOLEntities db = new SEDESOLEntities()) { using (var transaction = db.Database.BeginTransaction()) { try { string msj = string.Empty; CAPTURE_APPROVAL app = new CAPTURE_APPROVAL(); app.Id_Capture = dto.Id_Capture; app.Id_User = dto.Id_User; app.Id_Status = approveStatus; app.CreateDate = DateTime.Now; db.CAPTURE_APPROVAL.Add(app); if (db.SaveChanges() > 0) { dto.Id = app.Id; msj = "SUCCESS"; } else { return("ERROR"); } CAPTURE b = db.CAPTUREs.FirstOrDefault(v => v.Id == dto.Id_Capture); if (b != null) { b.Id_Status = dto.Id_Status; b.Id_LevelApproval = level; db.SaveChanges(); msj = "SUCCESS"; } else { transaction.Rollback(); return("ERROR"); } transaction.Commit(); return(msj); } catch (Exception ex) { transaction.Rollback(); return("ERROR"); } } } }
public UserDTO Save(UserDTO dto) { using (SEDESOLEntities db = new SEDESOLEntities()) { USER sk = db.USERs.FirstOrDefault(v => v.Id == dto.Id); if (sk != null) { sk.Name = dto.Name; sk.Username = dto.Username; if (dto.Password != string.Empty) { sk.Password = dto.Password; } sk.LastName = dto.LastName; sk.PhoneNumber = dto.PhoneNumber; sk.Email = dto.Email; sk.Dni = dto.Dni; sk.Id_User_Type = dto.Id_User_Type; if (db.SaveChanges() > 0) { dto.Id = sk.Id; dto.Message = "SUCCESS"; } } else { sk = new USER(); sk.Name = dto.Name; sk.Username = dto.Username; sk.Password = dto.Password; sk.LastName = dto.LastName; sk.PhoneNumber = dto.PhoneNumber; sk.Email = dto.Email; sk.Dni = dto.Dni; sk.Id_User_Type = dto.Id_User_Type; sk.IsActive = true; db.USERs.Add(sk); if (db.SaveChanges() > 0) { dto.Id = sk.Id; dto.Message = "SUCCESS"; } } return(dto); } }
public string Delete(int id) { string result = ""; try { using (SEDESOLEntities db = new SEDESOLEntities()) { ATTENDANCE att = db.ATTENDANCEs.FirstOrDefault(v => v.Id == id); if (att != null) { db.ATTENDANCEs.Remove(att); db.SaveChanges(); result = "SUCCESS"; } else { result = "No se pudo eliminar la asistencia."; } } } catch (Exception ex) { result = "No se pudo eliminar la asistencia"; } return(result); }
public string DeleteUserSoupKitchen(int idSk, int idUser) { string result = ""; try { using (SEDESOLEntities db = new SEDESOLEntities()) { USER_SOUP_KITCHEN att = db.USER_SOUP_KITCHEN.FirstOrDefault(v => v.Id_Soup_Kitchen == idSk && v.Id_User == idUser); if (att != null) { db.USER_SOUP_KITCHEN.Remove(att); db.SaveChanges(); result = "SUCCESS"; } else { result = "No se pudo desasociar el comedor."; } } } catch (Exception ex) { result = "No se pudo desasociar el comedor"; } return(result); }
public SkUserTypeDTOcs SaveUserTypeSK(SkUserTypeDTOcs dto) { try { using (SEDESOLEntities db = new SEDESOLEntities()) { SOUP_KITCHEN_USER_TYPE ut = db.SOUP_KITCHEN_USER_TYPE.FirstOrDefault(v => v.Id_UserType == dto.Id_UserType && v.Id_SoupKitchen == dto.Id_SoupKitchen); if (ut != null) { dto.Message = "Se ha ingresado previamente."; } else { ut = new SOUP_KITCHEN_USER_TYPE(); ut.Id_SoupKitchen = dto.Id_SoupKitchen; ut.Id_UserType = dto.Id_UserType; ut.IsActive = true; db.SOUP_KITCHEN_USER_TYPE.Add(ut); if (db.SaveChanges() > 0) { dto.Id = ut.Id; dto.Message = "SUCCESS"; } } return(dto); } } catch (Exception ex) { return(new SkUserTypeDTOcs()); } }
public string Delete(int id) { string result = ""; try { using (SEDESOLEntities db = new SEDESOLEntities()) { SOUP_KITCHEN_USER_TYPE att = db.SOUP_KITCHEN_USER_TYPE.FirstOrDefault(v => v.Id == id); if (att != null) { db.SOUP_KITCHEN_USER_TYPE.Remove(att); db.SaveChanges(); result = "SUCCESS"; } else { result = "No se pudo eliminar el nivel de aprobación."; } } } catch (Exception ex) { result = "No se pudo eliminar el nivel de aprobación"; } return(result); }
public string Delete(int id) { string result = ""; try { using (SEDESOLEntities db = new SEDESOLEntities()) { CAPTURE_IMAGE att = db.CAPTURE_IMAGE.FirstOrDefault(v => v.Id == id); if (att != null) { db.CAPTURE_IMAGE.Remove(att); db.SaveChanges(); result = "SUCCESS"; } else { result = "No se pudo eliminar el archivo."; } } } catch (Exception ex) { result = "No se pudo eliminar el archivo"; } return(result); }
public UserSoupKitchen SaveUserSoupKitchen(UserSoupKitchen dto) { try { using (SEDESOLEntities db = new SEDESOLEntities()) { USER_SOUP_KITCHEN ut = db.USER_SOUP_KITCHEN.FirstOrDefault(v => v.Id_User == dto.Id_User && v.Id_Soup_Kitchen == dto.Id_Soup_Kitchen); if (ut != null) { dto.Message = "Se ha ingresado previamente."; } else { ut = new USER_SOUP_KITCHEN(); ut.Id_Soup_Kitchen = dto.Id_Soup_Kitchen; ut.Id_User = dto.Id_User; ut.IsActive = true; db.USER_SOUP_KITCHEN.Add(ut); if (db.SaveChanges() > 0) { dto.Id = ut.Id; dto.Message = "SUCCESS"; } } return(dto); } } catch (Exception ex) { return(new UserSoupKitchen()); } }
public void DeactivateStatus(int id) { using (SEDESOLEntities entities = new SEDESOLEntities()) { STATUS status = entities.STATUS.Find(id); status.IsActive = false; entities.SaveChanges(); } }
public void DeactivateYear(int id) { using (SEDESOLEntities entities = new SEDESOLEntities()) { YEAR year = entities.YEARs.Find(id); year.IsActive = false; entities.SaveChanges(); } }
public void DeactivateMonth(int id) { using (SEDESOLEntities entities = new SEDESOLEntities()) { MONTH month = entities.MONTHs.Find(id); month.IsActive = false; entities.SaveChanges(); } }
public void ActivateState(int id) { using (SEDESOLEntities entities = new SEDESOLEntities()) { STATE state = entities.STATEs.Find(id); state.IsActive = true; entities.SaveChanges(); } }
public void Activate(int id) { using (SEDESOLEntities entities = new SEDESOLEntities()) { USER sk = entities.USERs.Find(id); sk.IsActive = true; entities.SaveChanges(); } }
public void Activate(int id) { using (SEDESOLEntities entities = new SEDESOLEntities()) { SOUP_KITCHEN sk = entities.SOUP_KITCHEN.Find(id); sk.IsActive = true; entities.SaveChanges(); } }
public void Activate(int id) { using (SEDESOLEntities entities = new SEDESOLEntities()) { CAPTURE b = entities.CAPTUREs.Find(id); b.IsActive = true; entities.SaveChanges(); } }
public void UpdateMonth(MonthDTO month, bool editar) { using (SEDESOLEntities entities = new SEDESOLEntities()) { if (editar) { MONTH existente = entities.MONTHs.FirstOrDefault(v => v.Id == month.Id); if (existente != null) { existente.Description = month.Description; entities.SaveChanges(); } } else { MONTH nueva = new MONTH(); nueva.Description = month.Description; nueva.IsActive = true; entities.MONTHs.Add(nueva); entities.SaveChanges(); } } }
public void UpdateYear(YearDTO year, bool editar) { using (SEDESOLEntities entities = new SEDESOLEntities()) { if (editar) { YEAR existente = entities.YEARs.FirstOrDefault(v => v.Id == year.Id); if (existente != null) { existente.Description = year.Description; entities.SaveChanges(); } } else { YEAR nueva = new YEAR(); nueva.Description = year.Description; nueva.IsActive = true; entities.YEARs.Add(nueva); entities.SaveChanges(); } } }
public void UpdateStatus(StatusDTO status, bool editar) { using (SEDESOLEntities entities = new SEDESOLEntities()) { if (editar) { STATUS existente = entities.STATUS.FirstOrDefault(v => v.Id == status.Id); if (existente != null) { existente.Description = status.Description; entities.SaveChanges(); } } else { STATUS nueva = new STATUS(); nueva.Description = status.Description; nueva.IsActive = true; entities.STATUS.Add(nueva); entities.SaveChanges(); } } }
public void UpdateState(StateDTO state, bool editar) { using (SEDESOLEntities entities = new SEDESOLEntities()) { if (editar) { STATE existente = entities.STATEs.FirstOrDefault(v => v.Id == state.Id); if (existente != null) { existente.Name = state.Name; entities.SaveChanges(); } } else { STATE nueva = new STATE(); nueva.Name = state.Name; nueva.IsActive = true; nueva.Abbreviation = string.Empty; entities.STATEs.Add(nueva); entities.SaveChanges(); } } }
public string EditStatus(int idStatus, int idCapture, int UserTypeId) { using (SEDESOLEntities db = new SEDESOLEntities()) { CAPTURE b = db.CAPTUREs.FirstOrDefault(v => v.Id == idCapture); if (b != null) { b.Id_Status = idStatus; b.Id_LevelApproval = UserTypeId; db.SaveChanges(); return("SUCCESS"); } else { return("El envío de captura no fue completado."); } } }
public int Save(CaptureImageDTO dto) { try { using (SEDESOLEntities db = new SEDESOLEntities()) { byte[] imgBytes; if (dto.FromCam) { imgBytes = Convert.FromBase64String(dto.ImageFileB64); } else { imgBytes = dto.ImageFile; } CAPTURE_IMAGE captureEntity = new CAPTURE_IMAGE { Name = dto.Name, ImageFile = imgBytes, ImagePath = dto.ImagePath, Id_Capture = dto.Id_Capture }; db.CAPTURE_IMAGE.Add(captureEntity); if (db.SaveChanges() > 0) { dto.Id = captureEntity.Id; return(dto.Id); } else { return(0); } } } catch (Exception ex) { return(0); } }
public bool Update(CaptureDTO capture) { using (SEDESOLEntities db = new SEDESOLEntities()) { CAPTURE b = db.CAPTUREs.Find(capture.Id); b.Description = capture.Description; b.CreateDate = capture.CreateDate; b.IsActive = capture.IsActive; b.Id_Month = capture.Id_Month; b.Id_Year = capture.Id_Year; b.Id_Status = capture.Id_Status; b.Id_SoupKitchen = (int)capture.Id_Soup_Kitchen; b.Folio = capture.Folio; b.InspectionCode = capture.InspectionCode; b.Id_LevelApproval = capture.Id_LevelApproval; b.Id_User = capture.Id_User; db.SaveChanges(); } return(true); }
public AttendanceDTO Save(AttendanceDTO att) { using (SEDESOLEntities db = new SEDESOLEntities()) { ATTENDANCE attendance = db.ATTENDANCEs.FirstOrDefault(v => v.Id == att.Id); if (attendance != null) { ATTENDANCE attendance2 = db.ATTENDANCEs.FirstOrDefault(v => v.Curp.Trim() == att.Curp.Trim() && v.Id_Capture == att.Id_Capture && v.Id != att.Id && v.IsAnonym == false); if (attendance2 != null && att.HasCurp == true) { att.Message = "Se ha ingresado previamente una asistencia."; } else { ATTENDANCE attendance3 = db.ATTENDANCEs.FirstOrDefault(v => v.Name.Trim().ToUpper() == att.Name.Trim().ToUpper() && v.LastName.Trim().ToUpper() == att.LastName.Trim().ToUpper() && v.LastName2.Trim().ToUpper() == att.LastName2.Trim().ToUpper() && v.Id_Capture == att.Id_Capture && v.Id != att.Id); if (attendance3 != null && att.IsAnonym == false) { att.Message = "Se ha ingresado previamente una asistencia."; } else { attendance.Id_Capture = att.Id_Capture; attendance.Birthdate = att.Birthdate; attendance.CreateDate = att.CreateDate; attendance.Curp = att.Curp.Trim(); attendance.IsActive = att.IsActive; attendance.LastName = att.LastName.Trim(); attendance.LastName2 = att.LastName2.Trim(); attendance.Quantity = att.Quantity; attendance.Name = att.Name.Trim(); attendance.IsAnonym = att.IsAnonym; attendance.Gender = att.Gender; attendance.Id_Condition = att.Id_Condition; attendance.Id_State_Birth = att.Id_State_Birth; attendance.Address = att.Address; attendance.PhoneNumber = att.PhoneNumber; if (db.SaveChanges() > 0) { att.Id = attendance.Id; att.Message = "SUCCESS"; } } } } else { ATTENDANCE attendance2 = db.ATTENDANCEs.FirstOrDefault(v => v.Curp.Trim() == att.Curp.Trim() && v.Id_Capture == att.Id_Capture && v.IsAnonym == false); if (attendance2 != null && att.HasCurp == true) { att.Message = "Se ha ingresado previamente una asistencia."; } else { ATTENDANCE attendance3 = db.ATTENDANCEs.FirstOrDefault(v => v.Name.Trim().ToUpper() == att.Name.Trim().ToUpper() && v.LastName.Trim().ToUpper() == att.LastName.Trim().ToUpper() && v.LastName2.Trim().ToUpper() == att.LastName2.Trim().ToUpper() && v.Id_Capture == att.Id_Capture && v.Id != att.Id); if (attendance3 != null && att.IsAnonym == false) { att.Message = "Se ha ingresado previamente una asistencia."; } else { attendance = new ATTENDANCE(); attendance.Id_Capture = att.Id_Capture; attendance.Birthdate = att.Birthdate; attendance.CreateDate = att.CreateDate; attendance.Curp = att.Curp.Trim(); attendance.IsActive = att.IsActive; attendance.LastName = att.LastName.Trim(); attendance.LastName2 = att.LastName2.Trim(); attendance.Quantity = att.Quantity; attendance.Name = att.Name.Trim(); attendance.IsAnonym = att.IsAnonym; attendance.Gender = att.Gender; attendance.Id_Condition = att.Id_Condition; attendance.Id_State_Birth = att.Id_State_Birth; attendance.Address = att.Address; attendance.PhoneNumber = att.PhoneNumber; db.ATTENDANCEs.Add(attendance); if (db.SaveChanges() > 0) { att.Id = attendance.Id; att.Message = "SUCCESS"; } } } } return(att); } }
public CaptureDTO Save(CaptureDTO capture) { try { using (SEDESOLEntities db = new SEDESOLEntities()) { CAPTURE cap = db.CAPTUREs.FirstOrDefault(v => v.Id_Year == capture.Id_Year && v.Id_Month == capture.Id_Month && v.Id_SoupKitchen == capture.Id_Soup_Kitchen && capture.IsActive == true); if (cap != null) { capture.Message = "Se ha creado previamente una captura para el periodo seleccionado."; } else { INSPECTION_CODE code = db.INSPECTION_CODE.FirstOrDefault(v => v.Id_Year == capture.Id_Year && v.Id_Month == capture.Id_Month && v.InspectionCode == capture.InspectionCode); if (code == null) { capture.Message = "El Código de inspección ingresado es incorrecto"; } else { CAPTURE captureEntity = new CAPTURE { Description = capture.Description, CreateDate = capture.CreateDate, IsActive = capture.IsActive, Id_Month = capture.Id_Month, Id_Year = capture.Id_Year, Id_Status = capture.Id_Status, Id_SoupKitchen = (int)capture.Id_Soup_Kitchen, Folio = capture.Folio, InspectionCode = capture.InspectionCode, Id_LevelApproval = capture.Id_LevelApproval, Id_User = capture.Id_User }; db.CAPTUREs.Add(captureEntity); if (db.SaveChanges() > 0) { capture.Id = captureEntity.Id; capture.Message = "SUCCESS"; //var query = from st in db.STATUS // where st.Id == capture.Id_Status // select new StatusDTO // { // Id = captureEntity.STATUS.Id, // Description = captureEntity.STATUS.Description, // IsActive = captureEntity.STATUS.IsActive // }; //capture.Status = query.FirstOrDefault(); } else { return(new CaptureDTO()); } } } return(capture); } } catch (Exception ex) { return(new CaptureDTO()); } }
public SoupKitchenDTO Save(SoupKitchenDTO att) { using (SEDESOLEntities db = new SEDESOLEntities()) { SOUP_KITCHEN sk = db.SOUP_KITCHEN.FirstOrDefault(v => v.Id == att.Id); if (sk != null) { SOUP_KITCHEN sk2 = db.SOUP_KITCHEN.FirstOrDefault(v => v.Name == att.Name && v.Id_State == att.Id_State && v.Id != att.Id); if (sk2 != null) { att.Message = "El comedor ha sido ingresado previamente"; } else { sk.Name = att.Name; sk.Description = att.Description; sk.Capacity = att.Capacity; sk.Address = att.Address; sk.PhoneNumber = att.PhoneNumber; sk.ContactName = att.ContactName; //sk.IsActive = att.IsActive; sk.Id_State = att.Id_State; sk.AllowAnonym = att.AllowAnonym; sk.Folio = att.Folio; sk.Id_Region = att.Id_Region; if (db.SaveChanges() > 0) { att.Id = sk.Id; att.Message = "SUCCESS"; } } } else { SOUP_KITCHEN sk2 = db.SOUP_KITCHEN.FirstOrDefault(v => v.Name == att.Name && v.Id_State == att.Id_State); if (sk2 != null) { att.Message = "El comedor ha sido ingresado previamente"; } else { sk = new SOUP_KITCHEN(); sk.Name = att.Name; sk.Description = att.Description; sk.Capacity = att.Capacity; sk.Address = att.Address; sk.PhoneNumber = att.PhoneNumber; sk.ContactName = att.ContactName; sk.IsActive = true; sk.Id_State = att.Id_State; sk.AllowAnonym = att.AllowAnonym; sk.Folio = att.Folio; sk.Id_Region = att.Id_Region; db.SOUP_KITCHEN.Add(sk); if (db.SaveChanges() > 0) { att.Id = sk.Id; att.Message = "SUCCESS"; } } } return(att); } }
public string SaveDataRation(DataTable dt) { string result = "SUCCESS"; using (SEDESOLEntities db = new SEDESOLEntities()) { foreach (DataRow item in dt.Rows) { try { string folio = item["Folio_Comedor"].ToString(); SOUP_KITCHEN sk = db.SOUP_KITCHEN.FirstOrDefault(x => x.Folio == folio); if (sk != null) { int year = Convert.ToInt32(item["Year"].ToString()); int month = Convert.ToInt32(item["Month"].ToString()); // save ration table RATION rat = new RATION(); rat.Description = "carga de excel"; rat.IsActive = true; rat.Id_SoupKitchen = sk.Id; rat.Id_Month = Convert.ToInt32(item["Month"].ToString()); rat.Id_Year = Convert.ToInt32(item["Year"].ToString()); rat.RationQuantity = Convert.ToDecimal(item["Raciones"].ToString()); rat.CreateUser = "******"; rat.CreateDate = DateTime.Now; rat.HasCoupon = false; db.RATIONs.Add(rat); db.SaveChanges(); var coupList = db.COUPONs.Where(v => v.Id_Year == year && v.Id_Month == month && v.Id_SoupKitchen == sk.Id).ToList(); var yearDto = db.YEARs.FirstOrDefault(v => v.Id == year); int count; if (coupList != null) { count = coupList.Count() + 1; } else { count = 1; } string monthS = string.Empty; //string yearS = string.Empty; if (month.ToString().Count() == 1) { monthS = "0" + month.ToString(); } else { monthS = month.ToString(); } string sequential = sk.Folio + "-" + monthS + yearDto.Description.ToString().Substring(2, 2) + "-" + count.ToString(); COUPON cou = new COUPON(); cou.Description = "carga de excel"; cou.IsActive = true; cou.Id_SoupKitchen = sk.Id; cou.Id_Month = Convert.ToInt32(item["Month"].ToString()); cou.Id_Year = Convert.ToInt32(item["Year"].ToString()); cou.Id_Ration = rat.Id; cou.Sequential = sequential; cou.RationQuantity = Convert.ToDecimal(item["Raciones"].ToString()); cou.CreateUser = "******"; cou.CreateDate = DateTime.Now; db.COUPONs.Add(cou); db.SaveChanges(); #region Commented update option //RATION rat = db.RATIONs.FirstOrDefault(v => v.Id_Year == year && v.Id_Month == month && v.Id_SoupKitchen == sk.Id); //if (rat != null) //{ // rat.Description = "carga de excel"; // rat.IsActive = true; // rat.Id_SoupKitchen = sk.Id; // rat.Id_Month = Convert.ToInt32(item["Month"].ToString()); // rat.Id_Year = Convert.ToInt32(item["Year"].ToString()); // rat.RationQuantity = Convert.ToDecimal(item["Raciones"].ToString()); // rat.CreateUser = "******"; // rat.CreateDate = DateTime.Now; // rat.HasCoupon = false; // db.SaveChanges(); //} //else //{ // rat = new RATION(); // rat.Description = "carga de excel"; // rat.IsActive = true; // rat.Id_SoupKitchen = sk.Id; // rat.Id_Month = Convert.ToInt32(item["Month"].ToString()); // rat.Id_Year = Convert.ToInt32(item["Year"].ToString()); // rat.RationQuantity = Convert.ToDecimal(item["Raciones"].ToString()); // rat.CreateUser = "******"; // rat.CreateDate = DateTime.Now; // rat.HasCoupon = false; // db.RATIONs.Add(rat); // db.SaveChanges(); //} //COUPON cou = db.COUPONs.FirstOrDefault(v => v.Id_Year == year && v.Id_Month == month && v.Id_SoupKitchen == sk.Id); //COUPON cou = db.COUPONs.FirstOrDefault(v => v.Id_Ration == rat.Id); //if (cou != null) //{ // cou.Description = "carga de excel"; // cou.IsActive = true; // cou.Id_SoupKitchen = sk.Id; // cou.Id_Month = Convert.ToInt32(item["Month"].ToString()); // cou.Id_Year = Convert.ToInt32(item["Year"].ToString()); // cou.Id_Ration = rat.Id; // cou.RationQuantity = Convert.ToDecimal(item["Raciones"].ToString()); // cou.CreateUser = "******"; // cou.CreateDate = DateTime.Now; // //cou.HasCoupon = false; // db.SaveChanges(); //} //else //{ // cou = new COUPON(); // cou.Description = "carga de excel"; // cou.IsActive = true; // cou.Id_SoupKitchen = sk.Id; // cou.Id_Month = Convert.ToInt32(item["Month"].ToString()); // cou.Id_Year = Convert.ToInt32(item["Year"].ToString()); // cou.Id_Ration = rat.Id; // cou.RationQuantity = Convert.ToDecimal(item["Raciones"].ToString()); // cou.CreateUser = "******"; // cou.CreateDate = DateTime.Now; // db.COUPONs.Add(cou); // db.SaveChanges(); //} #endregion } } catch (Exception ex) { return(ex.Message); } } } return(result); }
public InspectionCodeDTO Save(InspectionCodeDTO dto) { try { using (SEDESOLEntities db = new SEDESOLEntities()) { INSPECTION_CODE insCode = db.INSPECTION_CODE.FirstOrDefault(v => v.InspectionCode == dto.InspectionCode && v.Id_User == dto.Id_User); if (insCode != null) { dto.Message = "Se ha ingresado previamente el código generado."; } else { INSPECTION_CODE insCode2 = db.INSPECTION_CODE.FirstOrDefault(v => v.Id_Year == dto.Id_Year && v.Id_Month == dto.Id_Month && v.Id_User == dto.Id_User); if (insCode2 != null) { dto.Message = "Se ha generado previamente un código para el año y mes seleccionados."; } else { GEN_CODE_DAY genCode = db.GEN_CODE_DAY.FirstOrDefault(x => x.Id_Month == dto.Id_Month && x.Id_Year == dto.Id_Year); if (genCode == null) { dto.Message = "No se ha habilitado la generación de códigos para el mes y año seleccionados."; } else { DateTime dateToValidate = new DateTime(Convert.ToInt32(genCode.YEAR.Description), genCode.Id_Month, genCode.Day); if (DateTime.Today < dateToValidate) { dto.Message = "No se ha habilitado la generación de códigos para el mes y año seleccionados."; } else { INSPECTION_CODE insEntity = new INSPECTION_CODE { Id_Month = dto.Id_Month, Id_Year = dto.Id_Year, Id_User = dto.Id_User, InspectionCode = dto.InspectionCode }; db.INSPECTION_CODE.Add(insEntity); if (db.SaveChanges() > 0) { dto.Id = insEntity.Id; dto.Message = "SUCCESS"; } else { dto.Message = "Se ha producido un error al guardar el código de inspección"; } } } } } return(dto); } } catch (Exception ex) { return(new InspectionCodeDTO()); } }
public ProductDTO Save(ProductDTO prodDto) { using (SEDESOLEntities db = new SEDESOLEntities()) { using (var transaction = db.Database.BeginTransaction()) { try { //guardar producto PRODUCT product = db.PRODUCTs.FirstOrDefault(v => v.Id == prodDto.Id); if (product != null) { product.Description = prodDto.Description; product.Measure = prodDto.Measure; product.UnitMeasure = prodDto.UnitMeasure; product.Momio = prodDto.Momio; product.Price = 0; product.IsActive = prodDto.IsActive; product.EditUser = prodDto.EditUser; product.EditDate = prodDto.EditDate; if (db.SaveChanges() > 0) { prodDto.Id = product.Id; prodDto.Message = "SUCCESS"; } else { transaction.Rollback(); prodDto.Message = "Ha ocurriddo un error al guardar el producto."; return(prodDto); } } else { product = new PRODUCT(); product.Description = prodDto.Description; product.Measure = prodDto.Measure; product.UnitMeasure = prodDto.UnitMeasure; product.Momio = prodDto.Momio; product.Price = 0; product.IsActive = prodDto.IsActive; product.CreateUser = prodDto.CreateUser; product.CreateDate = prodDto.CreateDate; db.PRODUCTs.Add(product); if (db.SaveChanges() > 0) { prodDto.Id = product.Id; prodDto.Message = "SUCCESS"; } else { prodDto.Message = "Ha ocurriddo un error al guardar el producto."; transaction.Rollback(); return(prodDto); } } //guardar regiones del producto foreach (var item in prodDto.ListRegion) { //obtener si previamente ha sido guardada REGION_PRODUCT regionProd = db.REGION_PRODUCT.FirstOrDefault(v => v.Id_Product == prodDto.Id && v.Id_Region == item.Id); if (regionProd != null) { regionProd.Id_Region = item.Id; regionProd.Id_Product = prodDto.Id; regionProd.IsActive = item.IsActive; db.SaveChanges(); item.Id = regionProd.Id; prodDto.Message = "SUCCESS"; //if (db.SaveChanges() > 0) //{ // item.Id = regionProd.Id; // prodDto.Message = "SUCCESS"; //} //else //{ // prodDto.Message = "Ha ocurriddo un error al asociar la region al producto."; // transaction.Rollback(); // return prodDto; //} } else { regionProd = new REGION_PRODUCT(); regionProd.Id_Region = item.Id; regionProd.Id_Product = prodDto.Id; regionProd.IsActive = item.IsActive; db.REGION_PRODUCT.Add(regionProd); db.SaveChanges(); item.Id = regionProd.Id; prodDto.Message = "SUCCESS"; //if (db.SaveChanges() > 0) //{ // item.Id = regionProd.Id; // prodDto.Message = "SUCCESS"; //} //else //{ // prodDto.Message = "Ha ocurriddo un error al asociar la region al producto."; // transaction.Rollback(); // return prodDto; //} } } transaction.Commit(); return(prodDto); } //catch (DbEntityValidationException e) //{ // foreach (var eve in e.EntityValidationErrors) // { // //registrar errores en log // } // throw; //} catch (Exception ex) { transaction.Rollback(); prodDto.Message = "Ha ocurrido un error al guardar el producto."; return(prodDto); } } } }