Example #1
0
        public void Add(DepartmentVM d)
        {
            var data = mapper.Map <Department>(d);

            db.Departments.Add(data);
            db.SaveChanges();
        }
Example #2
0
        public IHttpActionResult Create(DepartmentVM department)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                if (_courseDepartmentService.Find(c => c.Code == department.Code) != null)
                {
                    ModelState.AddModelError(string.Empty, $"The Code {department.Code} Already Defined");
                }

                if (ModelState.Count > 0)
                {
                    return(BadRequest(ModelState));
                }

                if (_courseDepartmentService.Create(ModelBuilder.CreateDepartment(department)))
                {
                    return(Ok());
                }
                else
                {
                    return(InternalServerError());
                }
            }
            catch (Exception ex)
            {
                _loggingService.Write(ex);
                return(InternalServerError(ex));
            }
        }
Example #3
0
        public void Refresh_RefreshesActiveItemVM()
        {
            UserVM vm = CreateUserVMWithItems();

            var oldSelection = vm.Department;

            DepartmentVM oldSelectedItem = oldSelection
                                           .SelectedItem
                                           .GetValue(x => x.VM);

            string oldName = oldSelectedItem.GetValue(x => x.CachedName);

            string newName = "New name";

            vm.Source.Department.Name = newName;

            vm.Refresh(x => x.Department);

            var newSelection = vm.Department;

            DepartmentVM newSelectedItem = newSelection
                                           .SelectedItem
                                           .GetValue(x => x.VM);

            string actualName = newSelectedItem.GetValue(x => x.CachedName);

            Assert.AreEqual(newName, actualName);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            // Adds active class to menu Item (sidebar)
            Main master = (Main)this.Master;

            master.ActiveMenu("dhdash");

            Service.UtilityService.CheckRoles("DeptHead");
            empId    = Convert.ToInt32(Session["empId"]);
            dept     = Controllers.DepartmentCtrl.GetDept(empId);
            deptCode = dept.DeptCode;

            //hide for delegate
            if (empId == dept.DelegateApproverId)
            {
                btnRemoveDelegate.Disabled = true;
                ddlDelegate.Enabled        = false;
                btnAddDelegate.Disabled    = true;
                txtFromDate.Enabled        = false;
                txtToDate.Enabled          = false;
            }

            //get past 6 months
            var           lastSixMonths = Enumerable.Range(0, 7).Select(i => DateTime.Now.AddMonths(i - 6).ToString("MMMM" + " yyyy", CultureInfo.InvariantCulture)).Reverse();
            List <string> monthslist    = lastSixMonths.ToList();

            if (!IsPostBack)
            {
                BindEmpDDL();
                ddlMonth.DataSource = monthslist;
                ddlMonth.DataBind();
                GetDeleRep();
            }
        }
Example #5
0
        public IActionResult Create()
        {
            DepartmentVM department = new DepartmentVM();

            department.Companies = _context.Companies.ToList();
            return(View(department));
        }
Example #6
0
        public async Task <WrapperDepartmentListVM> Delete(DepartmentVM itemTemp)
        {
            IEnumerable <Department> itemTask = await _repositoryWrapper.Department.FindByConditionAsync(x => x.Id == itemTemp.Id && x.FactoryId == itemTemp.FactoryId);

            var item = itemTask.ToList().FirstOrDefault();

            if (item == null)
            {
                return(new WrapperDepartmentListVM());
            }
            _repositoryWrapper.Department.Delete(item);
            await _repositoryWrapper.Department.SaveChangesAsync();

            this._utilService.LogInfo("Successful In Deleting Item Cateory");

            var dataParam = new GetDataListVM()
            {
                FactoryId  = itemTemp.FactoryId,
                PageNumber = 1,
                PageSize   = 10,
                TotalRows  = 0
            };
            WrapperDepartmentListVM data = await GetListPaged(dataParam);

            return(data);
        }
Example #7
0
        public ActionResult Savedepartment(DepartmentVM model)
        {
            if (model.id == 0)
            {
                tbl_department deparment = new tbl_department();
                deparment.department_name = model.department_name.ToUpper();
                _departmentservice.CreateDepartment(deparment);
            }
            else
            {
                var findDep = _departmentservice.findDepartment(model.id);
                if (findDep == null)
                {
                    Warning("Department cannot be found", true);
                    return(View("EditDepartment"));
                }
                findDep.department_name = model.department_name;
                var success = _departmentservice.UpdateDepartment(findDep);
                if (success == true)
                {
                    Success("Department updated successfully!", true);
                    return(RedirectToAction("departments"));
                }
            }

            Success("Department created successfully");

            return(RedirectToAction("createdepartment"));
        }
        public ActionResult PostADepartment(string Name, string Description)
        {
            Department result = null;

            if (ModelState.IsValid)
            {
                var model = new Department
                {
                    Name         = Name,
                    Description  = Description,
                    CreationDate = GetCurrentDate()
                };
                result = _unitOfWork.Departments.AddADepartment(model);
                _unitOfWork.Complete();
            }

            var m = new DepartmentVM
            {
                RecID       = result.RecID,
                Name        = Name,
                Description = Description
            };



            return(PartialView("Degrees/_Department", m));
        }
        public ViewResult Update(int id)
        {
            DepartmentVM departmentVM = new DepartmentVM();

            departmentVM.department = _context.Departments.FirstOrDefault(x => x.Id == id);
            return(View(departmentVM));
        }
        //getDept by empId
        public static DepartmentVM GetDept(int empId)
        {
            DepartmentVM department = new DepartmentVM();

            using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext())
            {
                string deptCode = EmployeeBL.GetDeptCode(empId);
                department = entities.Departments.Where(d => d.DeptCode.Equals(deptCode))
                             .Select(d => new DepartmentVM()
                {
                    DeptCode           = d.DeptCode,
                    DeptName           = d.DeptName,
                    DeptCtcNo          = d.DeptCtcNo,
                    DeptFaxNo          = d.DeptFaxNo,
                    ColPtId            = d.ColPtId,
                    DeptHeadId         = d.DeptHeadId,
                    DeptRepId          = d.DeptRepId,
                    DelegateApproverId = d.DelegateApproverId,
                    DelegateFromDate   = d.DelegateFromDate,
                    DelegateToDate     = d.DelegateToDate,
                    EmpId = empId
                }).First <DepartmentVM>();
            }
            return(department);
        }
Example #11
0
        public async Task <IActionResult> List(string keyword)
        {
            var boCollection = await _BoRepository.GetAllAsyn();

            var boVMCollection = new List <DepartmentVM>();

            var couter = 0;

            foreach (var item in boCollection.OrderBy(x => x.SortCode))
            {
                var boVM = new DepartmentVM(item);
                boVM.OrderNumber = (++couter).ToString();
                boVMCollection.Add(boVM);
            }

            #region 为部门数据呈现处理名称缩进
            var deptItems = SelfReferentialItemFactory <Department> .GetCollection(boCollection.ToList(), true);

            foreach (var item in deptItems)
            {
                var dID  = Guid.Parse(item.ID);
                var dept = boVMCollection.FirstOrDefault(x => x.ID == dID);
                dept.Name = item.DisplayName;
            }
            #endregion

            return(PartialView("../../Views/BusinessOrganization/Department/_List", boVMCollection));
        }
Example #12
0
        public async Task <IActionResult> OnGet(int?departmentId)
        {
            PlantsList = _plantData.GetPlants()
                         .GetAwaiter().GetResult().Select(a => new SelectListItem
            {
                Value = a.PlantId.ToString(),
                Text  = a.Name
            });

            if (departmentId.HasValue)
            {
                Department.DepartmentId = departmentId.Value;
                var dep = await _departmentData.GetDepartments(Department);

                Department = dep.FirstOrDefault();
            }
            else
            {
                Department = new DepartmentVM();
            }
            if (Department == null)
            {
                return(RedirectToPage("./NotFound"));
            }

            return(Page());
        }
Example #13
0
        public ActionResult EmpDept()
        {
            ViewBag.Title = "Employee Dept Title";
            EmployeeVM empObj = new EmployeeVM
            {
                Id      = 1,
                Name    = "Rama",
                Email   = "*****@*****.**",
                Address = "Hyd",
            };

            DepartmentVM DeptObj = new DepartmentVM {
                Id = 10, Name = "Computer"
            };

            EmployeeDeptVM MainObj = new EmployeeDeptVM()
            {
                Employee   = empObj,
                Department = DeptObj
            };


            //MainObj.Employee = empObj;
            //MainObj.Department = DeptObj;

            return(View(MainObj));
        }
Example #14
0
        public void delete(DepartmentVM dpt)
        {
            Department d = db.Departments.Where(n => n.id == dpt.id).FirstOrDefault();

            db.Departments.Remove(d);
            db.SaveChanges();
        }
Example #15
0
        public JsonResult GetById(int Id)
        {
            var client = new HttpClient
            {
                BaseAddress = new Uri("https://localhost:44398/api/")
            };

            //Get the session with token and set authorize bearer token to API header
            client.DefaultRequestHeaders.Add("Authorization", HttpContext.Session.GetString("JWToken"));
            DepartmentVM departmentVM = null;
            var          responseTask = client.GetAsync("Departments/" + Id); //Access data from department API

            responseTask.Wait();                                              //Waits for the Task to complete execution.
            var result = responseTask.Result;

            if (result.IsSuccessStatusCode) // if access success
            {
                var json = JsonConvert.DeserializeObject(result.Content.ReadAsStringAsync().Result).ToString();
                departmentVM = JsonConvert.DeserializeObject <DepartmentVM>(json); //Tampung setiap data didalam departments
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Server Error");
            }
            return(Json(departmentVM));
        }
        public IActionResult InsertOrUpdate(DepartmentVM data, string id)
        {
            try
            {
                AuthController controller  = new AuthController();
                var            Session     = HttpContext.Session.GetString("id");
                var            json        = JsonConvert.SerializeObject(data);
                var            buffer      = System.Text.Encoding.UTF8.GetBytes(json);
                var            byteContent = new ByteArrayContent(buffer);
                byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Add("Authorization", HttpContext.Session.GetString("token"));
                if (data.Id == null)
                {
                    var result = client.PostAsync("departments/", byteContent).Result;
                    controller.SendLogs(Session + " Create role", Session);
                    return(Json(result));
                }
                else if (data.Id == id)
                {
                    var result = client.PutAsync("departments/" + id, byteContent).Result;
                    controller.SendLogs(Session + " Update role", Session);
                    return(Json(result));
                }

                return(Json(404));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #17
0
        public IActionResult PostDepartment(DepartmentVM vm)
        {
            try
            {
                var current = _mapper.Map <Departments>(vm);

                if (vm.Id == 0)
                {
                    int result = _depBll.Insert(current);

                    if (result != 1)
                    {
                        return(Json(new { add = true, done = false, message = "Error in Save" }));
                    }

                    return(Json(new { add = true, done = true, message = "Added Successfully" }));
                }
                else
                {
                    int result = _depBll.Update(current);

                    if (result != 1)
                    {
                        return(Json(new { edit = true, done = false, message = "Error in Update" }));
                    }

                    return(Json(new { edit = true, done = true, message = "Updated Successfully" }));
                }
            }
            catch (Exception x)
            {
                return(Json(new { done = false, message = $"{x.InnerException?.Message ?? x.Message}" }));
            }
        }
Example #18
0
        // GETBYID: Department

        public JsonResult GetById(int Id)
        {
            var client = new HttpClient
            {
                BaseAddress = new Uri("https://localhost:44343/api/")
            };

            //    client.DefaultRequestHeaders.Add("Authorization", HttpContext.Session.GetString("Token"));
            DepartmentVM departmentVM = null;
            var          responseTask = client.GetAsync("Department/" + Id);

            responseTask.Wait();
            var result = responseTask.Result;

            if (result.IsSuccessStatusCode)
            {
                var json = JsonConvert.DeserializeObject(result.Content.ReadAsStringAsync().Result).ToString();
                departmentVM = JsonConvert.DeserializeObject <DepartmentVM>(json);
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Server error try after some time.");
            }
            return(Json(departmentVM));
        }
Example #19
0
        public ActionResult Create()
        {
            EmployeeContext employeeContext = new EmployeeContext();
            var             vm = new DepartmentVM();

            return(View(vm));
        }
Example #20
0
        public OperationResult Insert(DepartmentVM model)
        {
            try
            {
                Department department = _DepartmentRepository.Entities.FirstOrDefault(c => c.DepartmentCode == model.DepartmentCode.Trim());
                if (department != null)
                {
                    return(new OperationResult(OperationResultType.Warning, "数据库中已经存在相同的部门信息,请修改后重新提交!"));
                }
                if (model.DepartmentName == null || model.DepartmentName.Trim() == "")
                {
                    return(new OperationResult(OperationResultType.Warning, "部门名称不能为空,请修改后重新提交!"));
                }
                var entity = new Department
                {
                    DepartmentCode = model.DepartmentCode,
                    DepartmentName = model.DepartmentName,
                    UpdateDate     = DateTime.Now
                };
                _DepartmentRepository.Insert(entity);

                return(new OperationResult(OperationResultType.Success, "新增数据成功!"));
            }
            catch
            {
                return(new OperationResult(OperationResultType.Error, "新增数据失败,数据库插入数据时发生了错误!"));
            }
        }
        public static department ToDto(DepartmentVM value, bool keepTree = false)
        {
            department d = new department();

            d.description = value.Description;
            d.id          = value.Id;
            d.code        = value.Code;
            d.name        = value.Name;
            if (value.JobPositions != null)
            {
                d.jobPositions = new List <jobPosition>();

                foreach (var jp in value.JobPositions)
                {
                    d.jobPositions.Add(JobPositionConvertUtil.ToDto(jp));
                }
            }
            d.parentDepartmentId = value.ParentDepartment?.Id;
            if (value.Leader != null)
            {
                // EmployeeConverter emConverter = new EmployeeConverter();
                // d.leader = emConverter.Convert(value.Leader);
            }
            if (keepTree && value.SubDepartments != null && value.SubDepartments.Count > 0)
            {
                d.subDepartments = new List <department>();
                foreach (var item in value.SubDepartments)
                {
                    d.subDepartments.Add(ToDto(item, true));
                }
            }
            return(d);
        }
        public ActionResult Create(DepartmentVM departmentVM)
        {
            if (ModelState.IsValid)
            {
                var user = Membership.GetUser(User.Identity.Name) as CustomMembershipUser;

                var department = new Department
                {
                    Name        = departmentVM.Name,
                    CreatedDate = DateTime.Now,
                    HoDId       = departmentVM.HoDId
                };

                if (user != null)
                {
                    department.CreatedById = user.UserId;
                }

                department.CreatedDate = DateTime.Now;

                db.Departments.Add(department);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.HoDId = new SelectList(db.Users, "Id", "Username", departmentVM.HoDId);
            return(View(departmentVM));
        }
 public dynamic PutDepartment(DepartmentVM d)
 {
     try
     {
         var department = db.Departments.Find(d.Id);
         department.Branch_Id              = d.BranchId;
         department.Department_A_Name      = d.NameA;
         department.Department_E_Name      = d.NameE;
         department.Department_Description = d.Description;
         department.Manager_ID             = d.ManagerId;
         department.User_ID     = d.UserId;
         department.Last_Update = DateTime.Now;
         var result = db.SaveChanges() > 0 ? true : false;
         return(new
         {
             result = result
         });
     }
     catch (Exception ex)
     {
         return(new
         {
             Message = ex.Message
         });
     }
 }
        public static DepartmentVM FromDto(DepartmentVM parent, department d)
        {
            DepartmentVM vm = new DepartmentVM();

            vm.Id          = d.id;
            vm.Code        = d.code;
            vm.Description = d.description;
            if (d.jobPositions != null)
            {
                foreach (jobPosition jp in d.jobPositions)
                {
                    JobPositionVM jpVm = JobPositionConvertUtil.FromDto(jp);
                    jpVm.Department = vm;
                    vm.JobPositions.Add(jpVm);
                }
            }
            if (d.leader != null)
            {
                vm.Leader = new EmployeeVM();
                // vm.Leader
            }
            vm.Name = d.name;

            vm.ParentDepartment = parent;
            if (d.subDepartments != null)
            {
                foreach (department subD in d.subDepartments)
                {
                    DepartmentVM subVM = FromDto(vm, subD);
                    vm.SubDepartments.Add(subVM);
                }
            }
            return(vm);
        }
Example #25
0
        public ActionResult List(string typeID, string keyword)
        {
            var tID          = Guid.Parse(typeID);
            var boCollection = _Service.FindBy(x => x.ParentDapartment.ID == tID).OrderBy(s => s.SortCode);

            var boVMCollection = new List <DepartmentVM>();
            var count          = 0;

            foreach (var bo in boCollection)
            {
                var boVM = new DepartmentVM(bo);
                boVM.OrderNumber = (++count).ToString();
                boVMCollection.Add(boVM);
                var addColItems = new List <CommonAlinkItem>()
                {
                    new CommonAlinkItem()
                    {
                        DisplayName     = "<span class=\"icon-user-3\"></span> 部门数据配置",
                        OnClickFunction = "javascript:departmentConfig(\"" + bo.ID + "\")"
                    },
                };
                boVM.AdditionOperateUrlItems = addColItems;
            }

            var updatedPartial = PageModelRepository <DepartmentVM> .PageUpdate(boVMCollection, null, null);

            return(Json(updatedPartial));
        }
Example #26
0
        public ActionResult DepartmentConfig(Guid id)
        {
            var bo   = _Service.GetSingle(id);
            var boVM = new DepartmentVM(bo);

            return(View("../../Views/Organization/Department/DepartmentConfig", boVM));
        }
Example #27
0
 public DepartmentModel(DepartmentVM model)
 {
     DepartmentId = model.DepartmentId;
     PlantId      = model.PlantId;
     Name         = model.Name;
     Description  = model.Description;
 }
Example #28
0
 public CourseDepartment CreateDepartment(DepartmentVM department)
 => Map(department, x => new CourseDepartment
 {
     Code      = x.Code,
     Name      = x.Name,
     IsDeleted = false
 });
Example #29
0
        public DepartmentVM getDepartId(string name)
        {
            DepartmentVM d = db.Departments.Where(n => n.DepartmentName == name).Select(n => new DepartmentVM {
                id = n.id, DepartmentCode = n.DepartmentCode, DepartmentName = n.DepartmentName
            }).FirstOrDefault();

            return(d);
        }
Example #30
0
        public async Task <IHttpActionResult> update([FromBody] DepartmentVM entity)
        {
            var result = await departmentService.UpdateAsync(entity);

            await LogData(entity.DEPT_CODE, entity.DEPT_ID.ToString());

            return(Ok(result));
        }