Пример #1
0
 /// <summary>
 /// 创建一个组织架构
 /// </summary>
 /// <param name="validationErrors">返回的错误信息</param>
 /// <param name="db">数据库上下文</param>
 /// <param name="entity">一个组织架构</param>
 /// <returns></returns>
 public bool Create(ref ValidationErrors validationErrors, Department entity)
 {
     try
     {
         repository.Create(entity);
         return(true);
     }
     catch (Exception ex)
     {
         validationErrors.Add(ex.Message);
         ExceptionsHander.WriteExceptions(ex);
     }
     return(false);
 }
Пример #2
0
        public void DepartmentRepository_Create()
        {
            DepartmentModel obj = GetDepartment();
            int             id  = respository.Create(obj);

            Assert.IsTrue(id > 0);
        }
Пример #3
0
        public void Create_Department_NewDepartmentEntityInContext()
        {
            var department = new Department
            {
                //CatalogEmployeeID = new List<int> { 1, 2 },
                ID   = 5,
                Name = "HR"
            };

            var departmentEntity = new DepartmentEntity
            {
                //CatalogEmployeeID = new List<int> { 1, 2 },
                ID   = 5,
                Name = "HR"
            };

            A.CallTo(() => _mapper.Map <Department, DepartmentEntity>(department)).Returns(departmentEntity);

            _repository.Create(department);
            var expectedMappedValue = _fakeContext.Departments.First(x => x.ID == 5);

            Assert.That(expectedMappedValue.ID, Is.EqualTo(5));
            Assert.That(expectedMappedValue.Name, Is.EqualTo("HR"));
            //Assert.That(expectedMappedValue.CatalogEmployeeID, Is.EquivalentTo(new[] { 1, 2 }));
        }
Пример #4
0
        public void Create(string[] args)
        {
            if (string.IsNullOrEmpty(currentTable))
            {
                Console.WriteLine("Please select a Table first");
                return;
            }
            switch (currentTable)
            {
            case "Address":
                addressRepository.Create(args);
                break;

            case "Company":
                companyRepository.Create(args);
                break;

            case "Department":
                departmentRepository.Create(args);
                break;

            case "Employee":
                employeeRepository.Create(args);
                break;
            }
        }
Пример #5
0
        public async Task <IActionResult> Create([FromBody] CreateDepartmentReq req)
        {
            var department = req.toEntity();
            await departmentRepo.Create(department);

            return(Created($"/api/departments/${department.Id}", department));
        }
Пример #6
0
 public IHttpActionResult Post(DepartmentModels department)
 {
     if (department.Name == "")
     {
         return(Content(HttpStatusCode.NotFound, "Failed To Add"));
     }
     departments.Create(department);
     return(Ok("Department Add Successfully"));
 }
Пример #7
0
 public IHttpActionResult Post(Department departments)
 {
     if ((departments.DepartmentName != null) && (departments.DepartmentName != ""))
     {
         department.Create(departments);
         return(Ok("Department Added Succesfully!")); //Status 200 OK
     }
     return(BadRequest("Failed to Add Department"));
 }
Пример #8
0
 public IHttpActionResult Post(Department department)
 {
     if ((department.Name != null) || (department.Name != ""))
     {
         departments.Create(department);
         return(Ok("Department Add Successfully!"));
     }
     return(BadRequest("Failed to Add Department"));
 }
 // POST API/Department
 public IHttpActionResult Post(Department departments)
 {
     if ((departments.DepartmentName != null) && (departments.DepartmentName != ""))
     {
         department.Create(departments);
         return(Ok("Department Insert Succesfully!"));
     }
     return(BadRequest("Failed to Insert Department"));
 }
Пример #10
0
 public IHttpActionResult Post(Department department)
 {
     if ((department.Name != null) && (department.Name != ""))
     {
         _repository.Create(department);
         return(Ok("Data Berhasil Diinput"));
     }
     return(BadRequest("Department Name Can't be null"));
 }
Пример #11
0
        public ActionResult Create(Department department)
        {
            if (ModelState.IsValid)
            {
                _department.Create(department);
                return(RedirectToAction("Index"));
            }

            return(View(department));
        }
Пример #12
0
        static Department CreateDept(string deptName, bool isActive)
        {
            var dept = new Department();

            dept.DeptID   = Guid.NewGuid();
            dept.DeptName = deptName;
            dept.IsActive = isActive;

            var repo    = new DepartmentRepository();
            var newDept = repo.Create(dept);

            return(newDept);
        }
Пример #13
0
        private void SaveBtn_Click(object sender, EventArgs e)
        {
            try
            {
                string id = "0";
                if (!IdTxt.Text.Equals(""))
                {
                    id = IdTxt.Text.ToString();
                }

                department.Id     = int.Parse(id);
                department.Name   = NameTxt.Text.ToString();
                department.Status = StatusCbx.SelectedIndex.ToString();

                Department item = new Department
                {
                    Id       = department.Id,
                    Name     = department.Name,
                    StatusId = _Context.Statuses
                               .Where(x => x.Id == (StatusCbx.SelectedIndex + 1))
                               .Select(x => x.Id)
                               .FirstOrDefault()
                };

                if (mode.Equals("Create"))
                {
                    departmentRepo.Create(item);
                }
                else
                {
                    departmentRepo.Update(item);
                }

                Close();

                MessageBox.Show(
                    text: "Registro guardado con exito",
                    caption: "Informacion",
                    buttons: MessageBoxButtons.OK,
                    icon: MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                MessageBox.Show(
                    text: "Error al guardar los datos",
                    caption: "Error",
                    buttons: MessageBoxButtons.OK,
                    icon: MessageBoxIcon.Error);
            }
        }
Пример #14
0
        static Department CreateDepartment(string departmentName, bool isActive)
        {
            var department = new Department
            {
                DepartmentID   = Guid.NewGuid(),
                DepartmentName = departmentName,
                IsActive       = isActive
            };

            var repository    = new DepartmentRepository();
            var newDepartment = repository.Create(department);

            return(newDepartment);
        }
        public IActionResult Create(Department item)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                return(Ok(_departmentRepository.Create(item)));
            }
            catch
            {
                return(BadRequest(ModelState)); //or can throw new Exception
            }
        }
        public void Create_Department_NewDepartmentEntityInContext()
        {
            //arrange
            var department = new Department()
            {
                CatalogEmployeeID = new List <int>(new int[] { 1, 2 }), ID = 5, Name = "HR"
            };
            var departmentEntity = new DepartmentEntity()
            {
                EmployeeID = new List <int> (new int[] { 1, 2 }), ID = 10, Name = "HR"
            };

            A.CallTo(() => _mapper.Map <Department, DepartmentEntity>(department)).Returns(departmentEntity);

            //act
            _repository.Create(department);

            //assert
            Assert.AreEqual(departmentEntity, _fakeContext.Departments.Last());
        }
        public void CreateDepartmentSavesADepartmentViaContext()
        {
            var mockSet = new Mock <DbSet <Department> >();

            var mockContext = new Mock <PaDbContext>();

            mockContext.Setup(m => m.Departments).Returns(mockSet.Object);

            var depsRepo = new DepartmentRepository(mockContext.Object);

            depsRepo.Create(new Department
            {
                EmployeeHeadId = -1,
                Name           = "Test Dep",
                Situation      = ""
            });

            mockSet.Verify(m => m.Add(It.IsAny <Department>()), Times.Once());
            mockContext.Verify(m => m.SaveChanges(), Times.Once());
        }
Пример #18
0
        public ActionResult Create(Department model)
        {
            ViewBag.Head = "Manage Departments";
            ViewBag.Form = "Departments Registration";

            if (ModelState.IsValid)
            {
                try
                {
                    _rep.Create(model);
                    return(RedirectToAction("Index"));
                }
                catch (Exception)
                {
                    throw;
                }
            }
            else
            {
                return(View(model));
            }
        }
Пример #19
0
        public HttpResponseMessage Post(Department model)
        {
            try
            {
                int id = repository.Create(model);
                if (id != zero)
                {
                    model.Id           = id;
                    response.MessageOk = new MessageOk()
                    {
                        Code        = "C001",
                        Description = "El departamento se creo correctamente.",
                    };
                    response.Data = model;

                    return(Request.CreateResponse(HttpStatusCode.OK, response));
                }

                response.MessageError = new MessageError()
                {
                    Code        = "C001",
                    Description = "Error al crear el departamento.",
                };
                response.Data = model;

                return(Request.CreateResponse(HttpStatusCode.BadRequest, response));
            }
            catch (Exception ex)
            {
                response.MessageError = new MessageError()
                {
                    Code        = "E001",
                    Description = "La petición se devolvio con errores.",
                };
                response.Data = ex;

                return(Request.CreateResponse(HttpStatusCode.InternalServerError, response));
            }
        }
Пример #20
0
 public void CreateDepartment(Department obj)
 {
     repository.Create(obj);
 }
Пример #21
0
        static Department CreateDepartment(Department newDepartment)
        {
            var repo = new DepartmentRepository();

            return(repo.Create(newDepartment));
        }
Пример #22
0
 // POST: api/Department
 public IHttpActionResult Post(Department department)
 {
     depRepo.Create(department);
     return(Ok("Department Successfully Added"));
 }
Пример #23
0
        public void CreateDepartment(Departments department)
        {
            DepartmentRepository repository = new DepartmentRepository();

            repository.Create(department);
        }
Пример #24
0
        public override void Execute()
        {
            IFormatter formatter = new BinaryFormatter();

            switch (_command)
            {
            case RequestTypes.EditPosition:
            {
                LoggerEvs.writeLog("Edit position");

                var posModel = (PositionModel)formatter.Deserialize(_stream);

                var pos = positionsRepo.Get(posModel.Id);

                pos.Name = posModel.Name;
                positionsRepo.Update(pos);

                formatter.Serialize(_stream, ResponseTypes.Data);

                LoggerEvs.writeLog("Position updated");
                break;
            }

            case RequestTypes.RemovePosition:
            {
                LoggerEvs.writeLog("Remove position");

                var posId = (int)formatter.Deserialize(_stream);

                var position = positionsRepo.Get(posId);
                positionsRepo.Delete(position);

                formatter.Serialize(_stream, ResponseTypes.Data);

                LoggerEvs.writeLog("Position removed");
                break;
            }

            case RequestTypes.CreatePosition:
            {
                LoggerEvs.writeLog("Creating position");

                var positionModel = (PositionModel)formatter.Deserialize(_stream);

                positionsRepo.Create(new Position
                    {
                        Name   = positionModel.Name,
                        Salary = 1
                    });

                formatter.Serialize(_stream, ResponseTypes.Data);

                LoggerEvs.writeLog("Position created");
                break;
            }

            case RequestTypes.CreateDep:
            {
                LoggerEvs.writeLog("Create department");

                var depModel = (DepartmentModel)formatter.Deserialize(_stream);

                depsRepo.Create(new Department
                    {
                        EmployeeHeadId = -1,
                        Name           = depModel.Name,
                        Situation      = " "
                    });

                formatter.Serialize(_stream, ResponseTypes.Data);

                LoggerEvs.writeLog("Department created");
                break;
            }

            case RequestTypes.EditDepartment:
            {
                LoggerEvs.writeLog("Edit department");

                var depModel = (DepartmentModel)formatter.Deserialize(_stream);

                var updates = new Department
                {
                    EmployeeHeadId = -1,
                    Id             = depModel.Id,
                    Name           = depModel.Name,
                    Situation      = ""
                };

                depsRepo.Update(updates);
                formatter.Serialize(_stream, ResponseTypes.Data);

                LoggerEvs.writeLog("Department updated");
                break;
            }

            case RequestTypes.RemoveDep:
            {
                LoggerEvs.writeLog("Remove department");

                var depId = (int)formatter.Deserialize(_stream);

                var dep = depsRepo.Get(depId);
                depsRepo.Delete(dep);

                formatter.Serialize(_stream, ResponseTypes.Data);

                LoggerEvs.writeLog("Department removed");
                break;
            }

            case RequestTypes.EditPayout:
            {
                LoggerEvs.writeLog("Update payout");

                var payoutEditModel = (EditPayoutModel)formatter.Deserialize(_stream);

                var payout = payoutsRepo.Get(payoutEditModel.PayoutId);

                payout.Sum = payoutEditModel.Sum;

                payoutsRepo.Update(payout);

                formatter.Serialize(_stream, new PayoutModel
                    {
                        Id  = payout.Id,
                        Sum = payout.Sum
                    });

                LoggerEvs.writeLog("Payout updated");
                break;
            }

            case RequestTypes.RemovePayout:
            {
                LoggerEvs.writeLog("Remove payout");

                var payoutId = (int)formatter.Deserialize(_stream);
                var payout   = payoutsRepo.Get(payoutId);
                payoutsRepo.Delete(payout);

                formatter.Serialize(_stream, ResponseTypes.Data);

                LoggerEvs.writeLog("Payout removed");
                break;
            }

            case RequestTypes.GetPayouts:
            {
                LoggerEvs.writeLog("Get payouts");

                var empId = (int)formatter.Deserialize(_stream);

                var payouts = payoutsRepo.GetAll()
                              .Where(x => x.EmployeeId == empId)
                              .Join(payoutTypesRepo.GetAll(), x => x.PayoutTypeId, y => y.Id, (x, y) => new PayoutModel
                    {
                        Id         = x.Id,
                        PayoutType = y.Name,
                        Sum        = x.Sum
                    })
                              .ToList();

                formatter.Serialize(_stream, payouts);

                LoggerEvs.writeLog("Payouts sent");
                break;
            }

            case RequestTypes.GetPayoutTypes:
            {
                LoggerEvs.writeLog("Get payout types");

                var payoutTypes = payoutTypesRepo.GetAll()
                                  .Select(x => new PayoutTypeModel
                    {
                        Id   = x.Id,
                        Name = x.Name
                    })
                                  .ToList();

                formatter.Serialize(_stream, ResponseTypes.Data);
                formatter.Serialize(_stream, payoutTypes);

                LoggerEvs.writeLog("Payout types sent");
                break;
            }

            case RequestTypes.CreatePayout:
            {
                LoggerEvs.writeLog("Assign payout");

                var assignPayout = (AssignPayoutModel)formatter.Deserialize(_stream);

                var payout = payoutsRepo.Create(new Payout()
                    {
                        EmployeeId   = assignPayout.EmployeeId,
                        PayoutTypeId = assignPayout.PayoutTypeId,
                        Sum          = assignPayout.Sum
                    });

                formatter.Serialize(_stream, ResponseTypes.Data);
                formatter.Serialize(_stream, payout.Id);

                LoggerEvs.writeLog("Payout assigned");
                break;
            }

            case RequestTypes.FireEmp:
            {
                LoggerEvs.writeLog("Fire emp");

                var empId = (int)formatter.Deserialize(_stream);

                var emp = empsRepo.Get(empId);
                empsRepo.Delete(emp);

                formatter.Serialize(_stream, ResponseTypes.Data);
                formatter.Serialize(_stream, empId);

                LoggerEvs.writeLog("Emp fired");
                break;
            }

            case RequestTypes.GetDepartments:
                LoggerEvs.writeLog("Get departments");

                var deps = depsRepo.GetAll()
                           .Select(x => new DepartmentModel
                {
                    Id   = x.Id,
                    Name = x.Name
                })
                           .ToList();

                formatter.Serialize(_stream, ResponseTypes.Data);
                formatter.Serialize(_stream, deps);

                LoggerEvs.writeLog("Departments sent");
                break;

            case RequestTypes.GetPositions:
                LoggerEvs.writeLog("Get positions");

                var positions = positionsRepo.GetAll()
                                .Select(x => new PositionModel
                {
                    Id   = x.Id,
                    Name = x.Name
                })
                                .ToList();

                formatter.Serialize(_stream, ResponseTypes.Data);
                formatter.Serialize(_stream, positions);

                LoggerEvs.writeLog("Positions sent");
                break;

            case RequestTypes.GetEmps:
                LoggerEvs.writeLog("Get emps request");
                var emps = empsRepo.GetAll()
                           .Join(positionsRepo.GetAll(), x => x.PositionId, y => y.Id, (x, y) => new
                {
                    Id           = x.Id,
                    FirstName    = x.FirstName,
                    LastName     = x.LastName,
                    MiddleName   = x.MiddleName,
                    Position     = y.Name,
                    DepartmentId = x.DepartmentId
                })
                           .Join(depsRepo.GetAll(), x => x.DepartmentId, y => y.Id, (x, y) => new EmployeeModel
                {
                    Department = y.Name,
                    Id         = x.Id,
                    FirstName  = x.FirstName,
                    LastName   = x.LastName,
                    MiddleName = x.MiddleName,
                    Position   = x.Position
                })
                           .ToList();

                formatter.Serialize(_stream, ResponseTypes.Data);

                formatter.Serialize(_stream, emps);
                LoggerEvs.writeLog("Emps sent");
                break;

            case RequestTypes.EditEmp:
            {
                LoggerEvs.writeLog("Edit emp request");
                var empFromRequuest = (EmployeeEditModel)formatter.Deserialize(_stream);

                try
                {
                    var position = positionsRepo.Get(empFromRequuest.PositionId);

                    var dep = depsRepo.Get(empFromRequuest.DepartmentId);

                    var emp = empsRepo.Get(empFromRequuest.Id);

                    emp.LastName     = empFromRequuest.LastName;
                    emp.MiddleName   = empFromRequuest.MiddleName;
                    emp.FirstName    = empFromRequuest.FirstName;
                    emp.DepartmentId = dep.Id;
                    emp.PositionId   = position.Id;

                    empsRepo.Update(emp);

                    formatter.Serialize(_stream, ResponseTypes.Data);

                    // Отправить обновленную информацию на клиент
                    formatter.Serialize(_stream, new EmployeeModel
                        {
                            Id         = emp.Id,
                            FirstName  = emp.FirstName,
                            LastName   = emp.LastName,
                            MiddleName = emp.LastName,
                            Department = dep.Name,
                            Position   = position.Name
                        });
                    LoggerEvs.writeLog("Emp updated, sending actual info");
                }
                catch (Exception ex)
                {
                    formatter.Serialize(_stream, ResponseTypes.Error);
                    formatter.Serialize(_stream, ex.Message);
                    Console.WriteLine(ex.Message);
                }
                break;
            }

            case RequestTypes.CreateEmp:
                LoggerEvs.writeLog("Create emp request");
                var newEmpModel = (EmployeeModel)formatter.Deserialize(_stream);

                try
                {
                    var position = positionsRepo.GetAll()
                                   .Where(x => x.Name == newEmpModel.Position)
                                   .FirstOrDefault();

                    var dept = depsRepo.GetAll()
                               .Where(x => x.Name == newEmpModel.Department)
                               .FirstOrDefault();

                    var emp = new Employee
                    {
                        FirstName    = newEmpModel.FirstName,
                        LastName     = newEmpModel.LastName,
                        MiddleName   = newEmpModel.MiddleName,
                        PositionId   = position.Id,
                        DepartmentId = dept.Id
                    };

                    emp = empsRepo.Create(emp);

                    formatter.Serialize(_stream, ResponseTypes.Data);
                    formatter.Serialize(_stream, new EmployeeModel
                    {
                        FirstName  = emp.FirstName,
                        LastName   = emp.LastName,
                        Id         = emp.Id,
                        MiddleName = emp.MiddleName,
                        Position   = position.Name,
                        Department = dept.Name
                    });

                    LoggerEvs.writeLog("Emp created");
                }
                catch (Exception ex)
                {
                    formatter.Serialize(_stream, ResponseTypes.Error);
                    formatter.Serialize(_stream, ex.Message);
                    Console.WriteLine(ex.Message);
                }
                break;

            case RequestTypes.CreatePayoutType:
                LoggerEvs.writeLog("Create payout type request");
                var newPayoutTypeModel = (PayoutTypeModel)formatter.Deserialize(_stream);

                try
                {
                    payoutTypesRepo.Create(new PayoutType
                    {
                        Name = newPayoutTypeModel.Name
                    });

                    formatter.Serialize(_stream, ResponseTypes.Data);

                    LoggerEvs.writeLog("Payout type created");
                }
                catch (Exception ex)
                {
                    formatter.Serialize(_stream, ResponseTypes.Error);
                    formatter.Serialize(_stream, ex.Message);
                    Console.WriteLine(ex.Message);
                }
                break;

            case RequestTypes.EditPayoutType:
            {
                LoggerEvs.writeLog("Edit payout type");

                var payoutType = (PayoutTypeModel)formatter.Deserialize(_stream);

                var pt = payoutTypesRepo.Get(payoutType.Id);

                pt.Name = payoutType.Name;

                payoutTypesRepo.Update(pt);

                formatter.Serialize(_stream, ResponseTypes.Data);

                LoggerEvs.writeLog("Payout type updated");
                break;
            }

            case RequestTypes.RemovePayoutType:
            {
                LoggerEvs.writeLog("Remove payout type");

                var payoutTypeId = (int)formatter.Deserialize(_stream);

                var payoutType = payoutTypesRepo.Get(payoutTypeId);
                payoutTypesRepo.Delete(payoutType);

                formatter.Serialize(_stream, ResponseTypes.Data);

                LoggerEvs.writeLog("Payout type removed");
                break;
            }
            }
        }