public string SaveDepartment(DepartmentModels departmentModel) { DepartmentDTO department = new DepartmentDTO(); MessageDTO message = new MessageDTO(); department.Company = new CompanyDTO { CompanyId = Convert.ToInt32(departmentModel.CompanyId) }; department.DepartmentDescription = departmentModel.DepartmentDescription; department.DepartmentId = Convert.ToInt32(departmentModel.Id); department.DepartmentStatus = departmentModel.DepartmentStatus; department.SpendingCenter = new SpendingCenterDTO { SpendingCenterId = Convert.ToInt32(departmentModel.SpendingCenterId) }; department.User = new UserDTO { UserId = Convert.ToInt32(departmentModel.UserId) }; if (String.Compare(departmentModel.Operation, "add", StringComparison.Ordinal) == 0) { message = business.SaveDepartment(department, "I"); } else if (String.Compare(departmentModel.Operation, "edit", StringComparison.Ordinal) == 0) { message = business.SaveDepartment(department, "U"); } JavaScriptSerializer oSerializer = new JavaScriptSerializer(); string sJSON = oSerializer.Serialize(message); return(sJSON); }
public IHttpActionResult Put(int Id, DepartmentModels department) { //var dept_id = conn.Departments.FirstOrDefault(x => x.Id == Id); //if (dept_id == null) //{ // return Content(System.Net.HttpStatusCode.NotFound, "Id not found"); //} //else if (department.Name == "") //{ // return Content(System.Net.HttpStatusCode.NotFound, "Name cannot empty"); //} //else //{ // departments.Update(Id, department); // return Ok("Update successfully"); //} var put = departments.Update(Id, department); if (put > 0) { return(Ok("Department Update Successfully")); } return(BadRequest("Failed to Update Department")); }
public IHttpActionResult Post(DepartmentModels department) { if (department.Name == "") { return(Content(HttpStatusCode.NotFound, "Failed To Add")); } departments.Create(department); return(Ok("Department Add Successfully")); }
public int Create(DepartmentModels department) { //throw new NotImplementedException(); var procName = "SP_InsertDepartment"; parameters.Add("@Name", department.Name); var create = conn.Execute(procName, parameters, commandType: CommandType.StoredProcedure); return(create); }
public int Update(int Id, DepartmentModels department) { //throw new NotImplementedException(); var procName = "SP_UpdateDepartment"; parameters.Add("@Id", Id); parameters.Add("@Name", department.Name); var update = conn.Execute(procName, parameters, commandType: CommandType.StoredProcedure); return(update); }
public IHttpActionResult CreateDepartments(DepartmentModels model) { var response = new DataResponse <EntityDepartments>(); var entitydepartments = new EntityDepartments(); entitydepartments.DepartmentName = model.DepartmentName; entitydepartments.Description = model.Description; entitydepartments.BusinessId = CurrentBusinessId; entitydepartments.CreatedBy = CurrentUserId; entitydepartments.CreatedOn = DateTime.UtcNow; entitydepartments.DepartmentPrivilege = model.DepartmentPrivilege; response = repository.Insert(entitydepartments); return(Ok <DataResponse>(response)); }
public IHttpActionResult UpdateDepartment(DepartmentModels model) { var response = new DataResponse <EntityDepartments>(); if (ModelState.IsValid) { var entityDepartments = new EntityDepartments(); entityDepartments.Id = model.Id; entityDepartments.DepartmentName = model.DepartmentName; entityDepartments.Description = model.Description; entityDepartments.IsActive = model.IsActive; entityDepartments.UpdatedBy = CurrentUserId; entityDepartments.UpdatedOn = System.DateTime.UtcNow; entityDepartments.DepartmentPrivilege = model.DepartmentPrivilege; response = repository.Update(entityDepartments); } return(Ok <DataResponse>(response)); }
public static List <DepartmentModels> GetAllDepartment() { SqlConnection con = new SqlConnection(connection); SqlCommand cmd = new SqlCommand("usp_Department_GetAll", con); cmd.CommandType = CommandType.StoredProcedure; con.Open(); SqlDataReader reader = cmd.ExecuteReader(); List <DepartmentModels> dpmodels = new List <DepartmentModels>(); while (reader.Read()) { DepartmentModels models = new DepartmentModels(); models.DepartName = DBNull.Value != reader["DepartmentName"] ? (string)reader["DepartmentName"] : default(string); models.Id = DBNull.Value != reader["Id"] ? (int)reader["Id"] : default(int); dpmodels.Add(models); } reader.Close(); con.Close(); return(dpmodels); }
public ActionResult addDepartment(DepartmentModels pModel) { DepartmentCOMMON unDpto = new DepartmentCOMMON(); unDpto.Name = pModel.Name; List <DepartmentCOMMON> theList = new List <DepartmentCOMMON>(); if (Session["LaLista"] != null) { theList = (List <DepartmentCOMMON>)Session["LaLista"]; } theList.Add(unDpto); Fachada Fachada = new Fachada(); Fachada.Department_Add(unDpto); Session["LaLista"] = theList; #region Vaciar Textboxs pModel.mensaje = "Ingreso Correcto"; #endregion return(View(pModel)); }
private void Initialize() { List <string> Product_List = ProductID.Split(',').ToList(); Db2HoldReason.Conditions = string.Format("where lot_type='Production' and prodspec_id in ('{2}') and claim_time between '{0}' and '{1}'", StartTime.ToString("yyyy-MM-dd HH:mm:ss"), EndTime.ToString("yyyy-MM-dd HH:mm:ss"), string.Join("','", Product_List)); var Models = Db2HoldReason.GetEntities().EntityList; //if (Models.Count == 0) return; //lotCount int lotCount = Models.Select(s => s.Lot_ID).Distinct().Count(); //所有Hold数据 var HoldModels = Models.Where(w => w.Hold_Type != "" && w.Ope_Category.Substring(w.Ope_Category.Length - 4) == "Hold"); //5码的Hold数据 var HoldModels_5 = HoldModels.Where(w => w.Hold_Reason_Code.Length == 5); //4码的hold数据 var HoldModels_4 = HoldModels.Where(w => w.Hold_Reason_Code.Length == 4); List <FRPD> PD_List = new List <FRPD>(); if (HoldModels_4.Count() > 0) { PDCatcher.Conditions = string.Format("where pd_id in ('{0}')", string.Join("','", HoldModels_4.Select(s => s.PD_ID))); PD_List = PDCatcher.GetEntities().EntityList.ToList(); } var Departments = DepartmentCatcher.GetEntities().EntityList; foreach (var department in Departments) { //对每个部门计算该部门对应的hold list var list5 = HoldModels_5.Where(w => w.Hold_Reason_Code.Substring(0, 1) == department.Code_ID); var list4 = HoldModels_4.Where(w => PD_List.Where(p => p.Department == department.Code_ID).DefaultIfEmpty().Select(s => s.PD_ID).Contains(w.PD_ID)); var list = list4.Union(list5); List <ReqRpt014DepartmentTableEntity> l = new List <ReqRpt014DepartmentTableEntity>(); if (list.Count() == 0) //如果没有元素,则不进行查找 { DepartmentModels.Add(new ReqRpt014DepartmentTableModel(l) { Department = department.Description }); continue; } //如果存在元素,则进行下去 var ReasonList = list.GroupBy(g => g.Hold_Reason_Code).Select(s => new { Hold_Reason_Code = s.Key, Hold_Count = s.Count() }); foreach (var item in ReasonList) { ReqRpt014DepartmentTableEntity tableEntity = new ReqRpt014DepartmentTableEntity() { HoldCode = item.Hold_Reason_Code, HoldRate = item.Hold_Count / lotCount, LotCount = list.Where(w => w.Hold_Reason_Code == item.Hold_Reason_Code).Select(s => s.Lot_ID).Distinct().Count() }; l.Add(tableEntity); } DepartmentModels.Add(new ReqRpt014DepartmentTableModel(l) { Department = department.Description }); } //by product部分 foreach (string prod in Product_List) { var list = HoldModels.Where(s => s.ProdSpec_ID == prod); List <ReqRpt014ProductTableEntity> l = new List <ReqRpt014ProductTableEntity>(); if (list is null) //如果没有元素,则不进行查找 { ProductModels.Add(new ReqRpt014ProductTableModel(l) { ProductID = prod }); continue; } //如果存在元素,则进行下去 var ReasonList = list.GroupBy(g => g.Hold_Reason_Code).Select(s => new { Hold_Reason_Code = s.Key, HoldCount = s.Count() }); foreach (var item in ReasonList) { ReqRpt014ProductTableEntity tableEntity = new ReqRpt014ProductTableEntity() { HoldCode = item.Hold_Reason_Code, HoldRate = item.HoldCount / lotCount, LotCount = list.Where(w => w.Hold_Reason_Code == item.Hold_Reason_Code).Select(s => s.Lot_ID).Distinct().Count() }; l.Add(tableEntity); } ProductModels.Add(new ReqRpt014ProductTableModel(l) { ProductID = prod }); } }