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());
            }
        }
        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());
            }
        }
Exemplo n.º 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);
            }
        }
        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());
            }
        }
Exemplo n.º 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);
        }
        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());
            }
        }
 public bool Add(Department entity)
 {
     if (entity == null || entity.Name == "")
     {
         return(false);
     }
     return(departmentRepository.Add(entity));
 }
Exemplo n.º 8
0
        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));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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));
        }
 public IActionResult Create([Bind("Name")] Department department)
 {
     if (ModelState.IsValid)
     {
         departmentRepository.Add(department);
         departmentRepository.Save();
         return(RedirectToAction(nameof(Index)));
     }
     return(View(department));
 }
Exemplo n.º 12
0
        public IActionResult Create(DepartmentModel departmentModel)
        {
            if (ModelState.IsValid)
            {
                _departmentRepo.Add(departmentModel);
                return(RedirectToAction(nameof(Index)));
            }

            return(View(departmentModel));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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));
 }
Exemplo n.º 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());
        }
Exemplo n.º 16
0
        public bool Add(Department department)
        {
            bool IsSaved = _repository.Add(department);

            if (IsSaved)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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"));
        }
        public JsonResult Create(Department department, string userid)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    IPD.Add(department, Session["userid"].ToString());
                }
            }
            catch
            {
                return(Json("error"));
            }

            return(Json("success"));
        }
Exemplo n.º 20
0
        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);
        }
        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));
            }
        }
Exemplo n.º 22
0
        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));
            }
        }
Exemplo n.º 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());
        }
Exemplo n.º 24
0
        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);
        }
Exemplo n.º 25
0
        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));
        }
Exemplo n.º 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));
 }
Exemplo n.º 28
0
 public void Add(Department department)
 {
     repository.Add(department);
     repository.Save();
 }
Exemplo n.º 29
0
 public ActionResult AddDepartment(Department department)
 {
     dRep.Add(department);
     return(RedirectToAction("DepartmentList"));
 }
Exemplo n.º 30
0
 public void AddDepartment(Department department)
 {
     departmentRepository.Add(department);
 }
 public bool Add(Department entity)
 {
     return(_departmentRepository.Add(entity));
 }
Exemplo n.º 32
0
 public IActionResult Post(Department department)
 {
     _departmentRepository.Add(department);
     return(CreatedAtAction("Get", new { id = department.Id }, department));
 }