public CResult <bool> UpdateSupplier(WebSupplier model) { LogHelper.Info(MethodBase.GetCurrentMethod().ToString()); LogHelper.Info("model", model); if (string.IsNullOrEmpty(model.ID)) { return(new CResult <bool>(false, ErrorCode.ParameterError)); } using (var context = new DeviceMgmtEntities()) { var entity = context.Supplier.FirstOrDefault(t => t.ID == model.ID && t.IsValid); if (entity == null) { return(new CResult <bool>(false, ErrorCode.SupplierNotExist)); } if (context.Supplier.Any(t => t.Name.ToUpper() == model.Name.ToUpper() && t.ProjectID == entity.ProjectID && t.IsValid && t.ID != model.ID)) { return(new CResult <bool>(false, ErrorCode.SupplierNameIsExist)); } entity.Name = model.Name; entity.Note = model.Note; entity.Address = model.Address; entity.Contact = model.Contact; entity.Mobile = model.Mobile; entity.Phone = model.Phone; context.Entry(entity).State = EntityState.Modified; return(context.Save()); } }
public ActionResult Edit(WebSupplier webSupplier) { try { var result = new SupplierBLL().UpdateSupplier(webSupplier); return(JsonContentHelper.GetJsonContent(result)); } catch { return(View()); } }
/// <summary> /// Bizs the supplier to web supplier. /// </summary> /// <param name="DataSupplier">The data supplier.</param> /// <returns>WebSupplier.</returns> public static WebSupplier BizSupplierToWebSupplier(this BizSupplier DataSupplier) { WebSupplier webSupplier = new WebSupplier { Id = DataSupplier.Id, SupplierName = DataSupplier.SupplierName, ContactNumer = DataSupplier.ContactNumer, Active = DataSupplier.Active, }; return(webSupplier); }
/// <summary> /// Webs the supplier to biz supplier. /// </summary> /// <param name="DataSupplier">The data supplier.</param> /// <returns>BizSupplier.</returns> public static BizSupplier WebSupplierToBizSupplier(this WebSupplier DataSupplier) { BizSupplier bizSupplier = new BizSupplier { Id = DataSupplier.Id, SupplierName = DataSupplier.SupplierName, ContactNumer = DataSupplier.ContactNumer, Active = DataSupplier.Active, }; return(bizSupplier); }
public IHttpActionResult Delete(WebSupplier webSupplier) { string response = crudFuction.BizDeleteSupplier(webSupplier.WebSupplierToBizSupplier()); if (!response.Equals("EXITO")) { return(BadRequest(response)); } else { return(Ok(response)); } }
public ActionResult Create(WebSupplier webSupplier) { try { webSupplier.ProjectID = this.GetCurrentProjectID(); webSupplier.CreateUserID = this.GetCurrentUserID(); var result = new SupplierBLL().InsertSupplier(webSupplier); return(JsonContentHelper.GetJsonContent(result)); } catch { return(View()); } }
public CResult <bool> InsertSupplier(WebSupplier model) { LogHelper.Info(MethodBase.GetCurrentMethod().ToString()); LogHelper.Info("model", model); if (string.IsNullOrEmpty(model.ProjectID)) { return(new CResult <bool>(false, ErrorCode.ParameterError)); } using (var context = new DeviceMgmtEntities()) { if (context.Project.Any(t => t.IsValid && t.ID == model.ProjectID) == false) { return(new CResult <bool>(false, ErrorCode.ProjectNotExist)); } if (context.Supplier.Any(t => t.Name.ToUpper() == model.Name.ToUpper() && t.ProjectID == model.ProjectID && t.IsValid)) { return(new CResult <bool>(false, ErrorCode.SupplierNameIsExist)); } var entity = new Supplier(); entity.CreateDate = DateTime.Now; entity.CreateUserID = model.CreateUserID; entity.ID = Guid.NewGuid().ToString(); entity.Name = model.Name; entity.IsValid = true; entity.Note = model.Note; entity.ProjectID = model.ProjectID; entity.Address = model.Address; entity.Contact = model.Contact; entity.Mobile = model.Mobile; entity.Phone = model.Phone; context.Supplier.Add(entity); return(context.Save()); } }
public CResult <WebSupplier> GetSupplierByID(string SupplierID) { LogHelper.Info(MethodBase.GetCurrentMethod().ToString()); LogHelper.Info("SupplierID", SupplierID); if (string.IsNullOrEmpty(SupplierID)) { return(new CResult <WebSupplier>(null, ErrorCode.ParameterError)); } using (var context = new DeviceMgmtEntities()) { var entity = context.Supplier.FirstOrDefault(t => t.ID == SupplierID && t.IsValid); if (entity == null) { return(new CResult <WebSupplier>(null, ErrorCode.SupplierNotExist)); } var model = new WebSupplier() { ID = entity.ID, Name = entity.Name, Address = entity.Address, Contact = entity.Contact, Mobile = entity.Mobile, Phone = entity.Phone, Note = entity.Note, CreateDate = entity.CreateDate, CreateUserID = entity.CreateUserID, CreateUserName = entity.User.Name, ProjectID = entity.ProjectID }; LogHelper.Info("result", model); return(new CResult <WebSupplier>(model)); } }