public HttpResponseMessage SaveProduct(string staffJson, string groupJson, string productTypeJson) { string staffId = ""; SqlTransaction tran = DataProvider.beginTrans(); try { CatSalestaffContract staff = JsonConvert.DeserializeObject <CatSalestaffContract>(staffJson); string[] mgntGroupIds = JsonConvert.DeserializeObject <string[]>(groupJson); string[] productTypeIds = JsonConvert.DeserializeObject <string[]>(productTypeJson); if (staff.Id > 0) { staffId = staffDT.Update(staff, tran); } else { staffId = staffDT.Insert(staff, tran); } deleteOldStaffGroup(staffId, tran); foreach (string groupID in mgntGroupIds) { StaffMgntgroupContract staffMgntGroup = new StaffMgntgroupContract() { Salestaffid = Converter.ToInt32(staffId), Managementgroupid = Converter.ToInt32(groupID) }; staffMgntGroupDT.Insert(staffMgntGroup, tran); } deleteOldProductType(staffId, tran); foreach (string productTypeId in productTypeIds) { StaffProducttypeContract staffProductypeContract = new StaffProducttypeContract() { Producttypeid = Converter.ToInt32(productTypeId), Salestaffid = Converter.ToInt32(staffId) }; staffProductTypeDT.Insert(staffProductypeContract, tran); } DataProvider.CommitTrans(tran); } catch (Exception e) { DataProvider.RollbackTrans(tran); ExceptionHandler.Log(e); return(null); } return(Request.CreateResponse <string>(HttpStatusCode.OK, staffId)); }
public HttpResponseMessage Save(string catsalestaffJson) { string errMessage = string.Empty; try { CatSalestaffContract catsalestaff = JsonConvert.DeserializeObject <CatSalestaffContract>(catsalestaffJson); businessRule.RegistInstants(catsalestaff); if (catsalestaff.Id == 0) { businessRule.RegistRule("Insert"); if (businessRule.CheckRules(out errMessage)) { return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Insert(catsalestaff))); } else { return(handleBRFailed(errMessage)); } } else { businessRule.RegistRule("Update"); if (businessRule.CheckRules(out errMessage)) { return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Update(catsalestaff))); } else { return(handleBRFailed(errMessage)); } } } catch (Exception e) { ExceptionHandler.Log(e); return(Request.CreateResponse <string>(HttpStatusCode.OK, "Có lỗi xảy ra trên chương trình.")); } }