コード例 #1
0
        public void ShouldDeleteDepartment()
        {
            // Arrange
            using (IEmployeeContext employeeContext = new EmployeeContext())
            {
                IDepartmentRepository departmentRepository = new DepartmentRepository(employeeContext);
                var department1 = CreateEntity.Department1;
                var department2 = CreateEntity.Department2;

                departmentRepository.Add(department1);
                departmentRepository.Add(department2);
                var numberOfAdds = +employeeContext.SaveChanges();

                // Act
                departmentRepository.Remove(department2);
                var numberOfDeletes = +employeeContext.SaveChanges();

                // Assert
                numberOfAdds.Should().BeGreaterThan(0);;
                numberOfDeletes.Should().BeGreaterThan(0);

                var allDepartments = departmentRepository.GetAll().ToList();
                allDepartments.Should().HaveCount(1);
                allDepartments.ElementAt(0).ShouldBeEquivalentTo(department1, options => options.IncludingAllDeclaredProperties());
            }
        }
コード例 #2
0
        public void ShouldDeleteDepartment()
        {
            // Arrange
            using (IEmployeeContext employeeContext = new EmployeeContext())
            {
                IDepartmentRepository departmentRepository = new DepartmentRepository(employeeContext);
                var department1 = CreateEntity.Department1;
                var department2 = CreateEntity.Department2;

                departmentRepository.Add(department1);
                departmentRepository.Add(department2);
                var numberOfAdds = +employeeContext.SaveChanges();

                // Act
                departmentRepository.Remove(department2);
                var numberOfDeletes =+ employeeContext.SaveChanges();

                // Assert
                numberOfAdds.Should().BeGreaterThan(0); ;
                numberOfDeletes.Should().BeGreaterThan(0);

                var allDepartments = departmentRepository.GetAll().ToList();
                allDepartments.Should().HaveCount(1);
                allDepartments.ElementAt(0).ShouldBeEquivalentTo(department1, options => options.IncludingAllDeclaredProperties());
            }
        }
コード例 #3
0
        public int SincronizeDepartmentWithBitrix()
        {
            Bitrix24Services _serviceBitrix  = new Bitrix24Services();
            WebhookServices  _serviceWebhook = new WebhookServices();

            try
            {
                IList <Webhook> lstWebhook = _serviceWebhook.GetWebhooks();
                DeleteAllDepartments();

                foreach (Webhook webhook in lstWebhook)
                {
                    IList <Department> lstDepartment = _serviceBitrix.GetDepartments(webhook.WebhookPath);

                    foreach (Department department in lstDepartment)
                    {
                        if (GetDepartmentsById(department.DepartmentId) == null)
                        {
                            department.WebhookId = webhook.WebhookID;
                            _departmentRepository.Add(department);
                        }
                    }
                }
                return(1);
            }
            catch (Exception ex)
            {
                return(0);
            }
        }
コード例 #4
0
        public void ShouldAddDepartment()
        {
            // Arrange
            using (IEmployeeContext employeeContext = new EmployeeContext())
            {
                IEmployeeRepository employeeRepository = new EmployeeRepository(employeeContext);
                employeeRepository.Add(CreateEntity.Employee1);
                employeeRepository.Add(CreateEntity.Employee2);
                employeeRepository.Add(CreateEntity.Employee3);
                employeeContext.SaveChanges();

                IDepartmentRepository departmentRepository = new DepartmentRepository(employeeContext);
                var department = CreateEntity.Department1;

                // Act
                departmentRepository.Add(department);
                var numberOfChangesCommitted = employeeContext.SaveChanges();

                // Assert
                numberOfChangesCommitted.Should().BeGreaterThan(0);

                var allDepartments = departmentRepository.GetAll().ToList();
                allDepartments.Should().HaveCount(1);
                allDepartments.ElementAt(0).ShouldBeEquivalentTo(department, options => options.IncludingAllDeclaredProperties());
            }
        }
コード例 #5
0
        public BaseResponse <Department> AddDepartment(Department model)
        {
            var response = new BaseResponse <Department>();
            var errors   = Validate <Department>(model, new DepartmentValidator());

            if (errors.Count() > 0)
            {
                BaseResponse <Department> errResponse = new BaseResponse <Department>(model, errors);
                errResponse.IsSuccess = false;
                return(errResponse);
            }
            try
            {
                var lstDepartment = _departmentRepository.GetAll().Where(n => n.Code.ToLower() == model.Code.ToLower()).ToList();
                if (lstDepartment.Count() == 0)
                {
                    model.CreatedOn = DateTime.Now;
                    response.Value  = _departmentRepository.Add(model);
                    _applicationLoggingRepository.Log("EVENT", "ADD", "Department", model.Id.ToString(), "", "", model, "", HttpContext.Current.Request.UserHostAddress, model.CreatedBy);
                }
                else
                {
                    response.Message   = "Mã đơn vị đã tồn tại";
                    response.IsSuccess = false;
                }
            }
            catch (Exception ex)
            {
                response.IsSuccess = false;
                response.Message   = "Error: " + ex.Message + " StackTrace: " + ex.StackTrace;
            }
            return(response);
        }
コード例 #6
0
        public void ShouldAddDepartment()
        {
            // Arrange
            using (IEmployeeContext employeeContext = new EmployeeContext())
            {
                IEmployeeRepository employeeRepository = new EmployeeRepository(employeeContext);
                employeeRepository.Add(CreateEntity.Employee1);
                employeeRepository.Add(CreateEntity.Employee2);
                employeeRepository.Add(CreateEntity.Employee3);
                employeeContext.SaveChanges();

                IDepartmentRepository departmentRepository = new DepartmentRepository(employeeContext);
                var department = CreateEntity.Department1;

                // Act
                departmentRepository.Add(department);
                var numberOfChangesCommitted = employeeContext.SaveChanges();

                // Assert
                numberOfChangesCommitted.Should().BeGreaterThan(0);

                var allDepartments = departmentRepository.GetAll().ToList();
                allDepartments.Should().HaveCount(1);
                allDepartments.ElementAt(0).ShouldBeEquivalentTo(department, options => options.IncludingAllDeclaredProperties());
            }
        }
コード例 #7
0
 public bool Add(Department entity)
 {
     if (entity == null || entity.Name == "")
     {
         return(false);
     }
     return(departmentRepository.Add(entity));
 }
コード例 #8
0
ファイル: DeptController.cs プロジェクト: mdmdlna/Exam
        public ActionResult AddNew(DeptViewModel deptViewModel)
        {
            ResultModel result = new ResultModel();
            department  dept   = new department();

            Mapper.Map(deptViewModel, dept);
            result.IsSuccess = _deptRep.Add(dept) > 0;
            return(Json(result));
        }
コード例 #9
0
        public void AddDepartments(Departments entity)
        {
            DepartmentRepository departmentsRepository = new DepartmentRepository();

            //InstructorRepository instructorRepository = new InstructorRepository();
            //Instructor instructor = instructorRepository.GetByID(entity.InstructorID);
            //entity.Instructor = instructor;
            departmentsRepository.Add(entity);
        }
コード例 #10
0
        public ActionResult Create([Bind(Include = "D_ID,D_Name,Manager")] Department department)
        {
            if (ModelState.IsValid)
            {
                _db.Add(department);
                return(RedirectToAction("Index"));
            }

            return(View(department));
        }
コード例 #11
0
 public IActionResult Create([Bind("Name")] Department department)
 {
     if (ModelState.IsValid)
     {
         departmentRepository.Add(department);
         departmentRepository.Save();
         return(RedirectToAction(nameof(Index)));
     }
     return(View(department));
 }
コード例 #12
0
        public IActionResult Create(DepartmentModel departmentModel)
        {
            if (ModelState.IsValid)
            {
                _departmentRepo.Add(departmentModel);
                return(RedirectToAction(nameof(Index)));
            }

            return(View(departmentModel));
        }
コード例 #13
0
        public void DepartmentTest()
        {
            var testDbContext        = new TestDbContext(this._testDbSets);
            var departmentRepository = new DepartmentRepository(testDbContext);

            departmentRepository.Add(this._departments[0]);

            var result         = departmentRepository.Find(d => d.Id == 1);
            var expectedResult = this._departments[0];

            result.Should().ShouldBeEquivalentTo(expectedResult);
        }
コード例 #14
0
 public bool Add(Department department)
 {
     if (department.OrganizationBranch == null)
     {
         return(false);
     }
     if (department.Name != null && ((department.Name == null) && (department.Name.Length <= 11)))
     {
         return(false);
     }
     return(repository.Add(department));
 }
コード例 #15
0
        public ActionResult Create(Department department)
        {
            if (ModelState.IsValid)
            {
                //db.Department.Add(department);
                repo.Add(department);
                repo.UnitOfWork.Commit();
                return(RedirectToAction("Index"));
            }
            ViewBag.InstructorID = new SelectList(repoPerson.All().OrderBy(p => p.FirstName), "ID", "FirstName");

            return(View());
        }
コード例 #16
0
        public bool Add(Department department)
        {
            bool IsSaved = _repository.Add(department);

            if (IsSaved)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #17
0
        public static void ManageDepartment(Department department, EntityState entityState)
        {
            IDepartmentRepository departmentRepository = new DepartmentRepository();

            if (entityState == EntityState.Added)
            {
                department.EntityState = EntityState.Added;
                departmentRepository.Add(department);
            }
            else
            {
                department.EntityState = entityState;
                departmentRepository.Update(department);
            }
        }
コード例 #18
0
        public ActionResult AddDepartment(Departments deparment)
        {
            Departments          updatedepartment = null;
            HumanResourceContext context          = new HumanResourceContext();

            if (deparment.Id == 0)
            {
                updatedepartment = deprepo.Add(deparment);
            }
            else
            {
                updatedepartment = deprepo.Update(deparment);
            }
            return(RedirectToAction("Department", "HumanResource"));
        }
コード例 #19
0
        public JsonResult Create(Department department, string userid)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    IPD.Add(department, Session["userid"].ToString());
                }
            }
            catch
            {
                return(Json("error"));
            }

            return(Json("success"));
        }
コード例 #20
0
ファイル: DepartmentService.cs プロジェクト: tw0r2/wms_rfid
        public bool Add(Department department, out string strResult)
        {
            strResult = string.Empty;
            bool result        = false;
            var  newDepartment = new Department();
            var  depart        = DepartmentRepository.GetQueryable().FirstOrDefault(d => d.ID == department.ParentDepartmentID);
            var  employee      = EmployeeRepository.GetQueryable().FirstOrDefault(e => e.ID == department.DepartmentLeaderID);
            var  company       = CompanyRepository.GetQueryable().FirstOrDefault(c => c.ID == department.CompanyID);
            var  departExist   = DepartmentRepository.GetQueryable().FirstOrDefault(d => d.DepartmentCode == department.DepartmentCode);

            if (departExist == null)
            {
                if (newDepartment != null)
                {
                    try
                    {
                        newDepartment.ID               = Guid.NewGuid();
                        newDepartment.DepartmentCode   = department.DepartmentCode;
                        newDepartment.DepartmentName   = department.DepartmentName;
                        newDepartment.ParentDepartment = depart ?? newDepartment;
                        newDepartment.DepartmentLeader = employee;
                        newDepartment.Description      = department.Description;
                        newDepartment.Company          = company;
                        newDepartment.UniformCode      = department.UniformCode;
                        newDepartment.IsActive         = department.IsActive;
                        newDepartment.UpdateTime       = DateTime.Now;
                        DepartmentRepository.Add(newDepartment);
                        DepartmentRepository.SaveChanges();
                        result = true;
                    }
                    catch (Exception ex)
                    {
                        strResult = "原因:" + ex.Message;
                    }
                }
                else
                {
                    strResult = "原因:找不到当前登陆用户!请重新登陆!";
                }
            }
            else
            {
                strResult = "原因:该编号已存在!";
            }
            return(result);
        }
コード例 #21
0
        public async Task <IHttpActionResult> PostDepartment(Department department)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var addedDepartment = await _repository.Add(department);

                return(Ok(addedDepartment));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
コード例 #22
0
ファイル: HomeController.cs プロジェクト: Owais53/amsdemo2
        public ActionResult Save(tblDepartment dep)
        {
            IDepartmentRepository objdep = new DepartmentRepository();

            if (dep.DepartmentId == 0)
            {
                objdep.Add(dep);
                objdep.Save();
                return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                objdep.Update(dep);
                objdep.Save();
                TempData["UpdateMessage"] = "Updated Successfully";
                return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #23
0
        static void Main(string[] args)
        {
            //two ways in which , we will show the use of generic repository
            //#1 : Use Generic Repository to perform CRUD operations on Employee
            //#2 : In case you have a specific operation, not covered by methods in generic repisotory, you can use a specific repository inheriting

            //specific method of the department repository
            DepartmentRepository depRep = new DepartmentRepository();

            depRep.SetDepartmentByEmployeeID(10);

            //other methods from generic repository
            depRep.Add(new Department());

            //shows how to use generic repository
            GenericRepository <Employee> gRecEmployee = new GenericRepository <Employee>();

            gRecEmployee.Add(new Employee());
        }
コード例 #24
0
ファイル: DepartmentService.cs プロジェクト: windygu/wms_rfid
        public bool Add(Department department)
        {
            var newDepartment = new Department();
            var depart        = DepartmentRepository.GetQueryable().FirstOrDefault(d => d.ID == department.ParentDepartmentID);
            var employee      = EmployeeRepository.GetQueryable().FirstOrDefault(e => e.ID == department.DepartmentLeaderID);
            var company       = CompanyRepository.GetQueryable().FirstOrDefault(c => c.ID == department.CompanyID);

            newDepartment.ID               = Guid.NewGuid();
            newDepartment.DepartmentCode   = department.DepartmentCode;
            newDepartment.DepartmentName   = department.DepartmentName;
            newDepartment.ParentDepartment = depart ?? newDepartment;
            newDepartment.DepartmentLeader = employee;
            newDepartment.Description      = department.Description;
            newDepartment.Company          = company;
            newDepartment.UniformCode      = department.UniformCode;
            newDepartment.IsActive         = department.IsActive;
            newDepartment.UpdateTime       = DateTime.Now;

            DepartmentRepository.Add(newDepartment);
            DepartmentRepository.SaveChanges();
            return(true);
        }
コード例 #25
0
ファイル: HomeController.cs プロジェクト: Owais53/amsdemo2
        public ActionResult CreateDepartments(tblDepartment dep)
        {
            IDepartmentRepository objdep = new DepartmentRepository();


            var check = objdep.GetAll().Where(a => a.DepartmentName == dep.DepartmentName).FirstOrDefault();

            if (check == null)
            {
                if (ModelState.IsValid)
                {
                    objdep.Add(dep);
                    objdep.Save();
                    TempData["SuccessMessage"] = "Department Created";
                    return(RedirectToAction("DepartmentList"));
                }
            }
            else
            {
                TempData["ErrorMessage"] = ("" + dep.DepartmentName + " Department already exists");
            }

            return(View(dep));
        }
コード例 #26
0
        public async Task <IHttpActionResult> Post([FromBody] DepartmentViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var newModel = Mapper.Map <DepartmentViewModel, Department>(viewModel);

            newModel.CreateUser = newModel.UpdateUser = User.Identity.Name;
            if (newModel.ParentId > 0)
            {
                var parent = await DepartmentRepository.GetSingleAsync(newModel.ParentId.Value);

                if (parent != null)
                {
                    newModel.AncestorIds = parent.GetAncestorIdsAsParent();
                }
            }

            DepartmentRepository.Add(newModel);
            await UnitOfWork.SaveChangesAsync();

            return(RedirectToRoute("", new { controller = "Department", id = newModel.Id }));
        }
 public bool Add(Department department)
 {
     return(_departmentRepository.Add(department));
 }
コード例 #28
0
 public void Add(Department department)
 {
     repository.Add(department);
     repository.Save();
 }
コード例 #29
0
 public ActionResult AddDepartment(Department department)
 {
     dRep.Add(department);
     return(RedirectToAction("DepartmentList"));
 }
コード例 #30
0
 public void AddDepartment(Department department)
 {
     departmentRepository.Add(department);
 }
コード例 #31
0
 public bool Add(Department entity)
 {
     return(_departmentRepository.Add(entity));
 }
コード例 #32
0
 public IActionResult Post(Department department)
 {
     _departmentRepository.Add(department);
     return(CreatedAtAction("Get", new { id = department.Id }, department));
 }