public bool SaveOrUpdateMember(MemberModel member)
 {
     if (String.IsNullOrEmpty(member.Code))
     {
         throw new InvalidException("Code is required.");
     }
     if (String.IsNullOrEmpty(member.Sidc))
     {
         throw new InvalidException("SIDC is required.");
     }
     if (member.Id == null || member.Id == 0)
     {
         if (member.MemberType == (int)UserType.AlphaMember && _member.Get(member.CompanyCode, member.ThanaId).Any(e => e.MemberType == (int)UserType.AlphaMember))
         {
             throw new InvalidException("Alpha member already in selected thana");
         }
         if (GetMemberBySidc(member.CompanyCode, member.Sidc) != null)
         {
             throw new InvalidException("Selected SIDC already have a member code");
         }
         MemberModel existMember = _member.Get(member.CompanyCode, member.Code).FirstOrDefault();
         if (existMember == null)
         {
             return(_member.Add(member));
         }
         else
         {
             throw new InvalidException($"{member.Code} already exist, try with another code.");
         }
     }
     else
     {
         return(_member.Update(member));
     }
 }
        public IActionResult AddEmployee(EmployeeRegisterViewModel model)
        {
            var UserId = HttpContext.Session.GetString("UserId");

            if (ModelState.IsValid)
            {
                var item = new Models.Account
                {
                    Branch       = _Employee.GetBranchById(int.Parse(model.Branch)),
                    Department   = _Employee.GetDepartmentById(int.Parse(model.Department)),
                    Company      = _Employee.GetCompanyById(int.Parse(model.Company)),
                    Position     = _Employee.GetPositionById(int.Parse(model.Position)),
                    Category     = _Employee.GetCategoryById(int.Parse(model.Category)),
                    EmployeeNo   = model.EmployeeNo,
                    FirstName    = model.FirstName,
                    LastName     = model.LastName,
                    MiddleName   = model.MiddleName,
                    CreatedBy    = UserId,
                    CreationDate = DateTime.Now,
                };
                _Employee.Add(item);
                return(RedirectToAction("Index"));
            }
            else
            {
                model.Companies   = this.Companies();
                model.Branches    = this.Branches();
                model.Departments = this.Departments();
                model.Positions   = this.Positions();
                return(RedirectToAction("AddEmployee", model));
            }
        }
Exemplo n.º 3
0
 public async Task <IActionResult> Create([Bind("EmployeeId,FirstName,LastName,MobileNumber")] Employee employee)
 {
     if (ModelState.IsValid)
     {
         _employee.Add(employee);
         return(RedirectToAction(nameof(Index)));
     }
     return(View(employee));
 }
 public IActionResult create(Employee eyl)
 {
     if (ModelState.IsValid)
     {
         Employee employee = _employeerepository.Add(eyl);
         return(RedirectToAction("Index", new { id = eyl.Id }));
     }
     return(View());
 }
Exemplo n.º 5
0
 public IActionResult Create(Employee model)
 {
     if (ModelState.IsValid)
     {
         _Employee.Add(model);
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
Exemplo n.º 6
0
 public ActionResult Create([Bind(Include = "EmployeeId,FirstName,LastName")] Employee employee)
 {
     if (ModelState.IsValid)
     {
         repository.Add(employee);
         unitOfWork.CommiteChanges();
         return(RedirectToAction("Index"));
     }
     return(View(employee));
 }
Exemplo n.º 7
0
        void _CompanyCreate()
        {
            var empTypes = company.EmployeeTypes();
            var rnd      = new Random();

            for (int i = 0; i < 5; i++)
            {
                var tp = empTypes.ElementAt(rnd.Next(3));
                var s0 = company.Add(
                    new Employee()
                {
                    Fio          = tp.Name + "_" + (i + 1),
                    EmployeeType = tp,
                    HiringTime   = DateTime.Now.AddMonths(-rnd.Next(10, 500))
                });

                Assert.NotNull(s0, "Error create user");

                for (int j = 0; j < 10; j++)
                {
                    if (s0.EmployeeType.IsPrimary)
                    {
                        continue;
                    }
                    tp = empTypes.ElementAt(rnd.Next(3));
                    var s1 = company.AddSubordinates(s0,
                                                     new Employee()
                    {
                        Fio          = tp.Name + "_" + (j + 1),
                        EmployeeType = tp,
                        HiringTime   = DateTime.Now.AddMonths(-rnd.Next(10, 500))
                    });
                    Assert.NotNull(s1, "Error create user");

                    for (int k = 0; k < 5; k++)
                    {
                        if (s1.EmployeeType.IsPrimary)
                        {
                            continue;
                        }
                        tp = empTypes.ElementAt(rnd.Next(3));
                        var s2 = company.AddSubordinates(s1,
                                                         new Employee()
                        {
                            Fio          = tp.Name + "_" + (k + 1),
                            EmployeeType = tp,
                            HiringTime   = DateTime.Now.AddMonths(-rnd.Next(10, 500))
                        });

                        Assert.NotNull(s2, "Error create user");
                    }
                }
            }
        }
        public JsonResult Add([FromBody] Employee model)
        {
            Employee employee = new Employee
            {
                Name       = model.Name,
                Address    = model.Address,
                BirthDay   = model.BirthDay,
                Department = model.Department
            };

            return(Json(_employee.Add(employee)));
        }
 public ActionResult Create(EDepartment d)
 {
     try
     {
         depRepo.Add(d);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
Exemplo n.º 10
0
        public ViewResult Add(Employee emp)
        {
            string id = (Request.Form["Id"]).ToString();

            emp.Id      = Convert.ToInt32(id);
            emp.Name    = Request.Form["Name"];
            emp.Address = Request.Form["Address"];
            string age = Request.Form["Age"];

            emp.Age  = Convert.ToInt32(age);
            emp.Mail = Request.Form["Mail"].ToString();
            employee.Add(emp);
            return(View(emp));
        }
Exemplo n.º 11
0
        public IActionResult Add(FlightData.Models.Employee newEmployee)
        {
            if (User.IsInRole("Admin") == false)
            {
                return(RedirectToAction("Index", "Home"));
            }
            var _newEmployee = new FlightData.Models.Employee
            {
                FirstName  = newEmployee.FirstName,
                LastName   = newEmployee.LastName,
                Job        = newEmployee.Job,
                TotalHours = 0
            };

            _employees.Add(_newEmployee);
            return(RedirectToAction("Index", "Employee"));
        }
        public IActionResult Create(EmployeeCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = ProcessUploadedFile(model);

                Employee newEmployee = new Employee
                {
                    Name       = model.Name,
                    Email      = model.Email,
                    Department = model.Department,
                    PhotoPath  = uniqueFileName
                };

                _employee.Add(newEmployee);
                return(RedirectToAction("details", new { id = newEmployee.Id }));
            }

            return(View());
        }
Exemplo n.º 13
0
        public async Task <IActionResult> Post([FromBody] Employee employee)
        {
            if (!ModelState.IsValid)
            {
                _logger.AddLog(BadRequest(ModelState).ToString(), BadRequest().GetType().ToString());
                return(BadRequest(ModelState));
            }

            try
            {
                await _employeeService.Add(employee);
            }
            catch (Exception E)
            {
                _logger.AddLog(E.ToString(), E.GetType().ToString());
                return(StatusCode(StatusCodes.Status406NotAcceptable));
            }

            return(StatusCode(StatusCodes.Status201Created));
        }
Exemplo n.º 14
0
 public ActionResult Create(EmployeeDepartmemtViewModel eE)
 {
     try
     {
         EEmployee e = new EEmployee
         {
             Id        = eE.Id,
             FirstName = eE.FirstName,
             LastName  = eE.LastName,
             Gender    = eE.Gender,
             Address   = eE.Address,
             Email     = eE.Email,
             Password  = eE.Password
         };
         empRepo.Add(e);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
Exemplo n.º 15
0
        public IActionResult Create(EmployeeViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = string.Empty;

                //if (model.Photo != null && model.Photo.Count >=1)
                //{
                //    foreach (IFormFile photo in model.Photo)
                //    {
                //        string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "images");

                //        uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Name + ".jpg";
                //        string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                //        photo.CopyTo(new FileStream(filePath, FileMode.Create));
                //    }


                //}
                if (model.Photo != null)
                {
                    string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "images");

                    uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Name + ".jpg";
                    string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                    model.Photo.CopyTo(new FileStream(filePath, FileMode.Create));
                }
                Employee newEmployee = new Employee
                {
                    Name       = model.Name,
                    Email      = model.Email,
                    Department = model.Department,
                    PhotoPath  = uniqueFileName
                };
                _employee.Add(newEmployee);
                return(RedirectToAction("Details", new { id = newEmployee.Id }));
            }
            return(View());
        }
Exemplo n.º 16
0
 public bool SaveOrUpdateSalesman(SalesmanModel salesman)
 {
     if (_salesman.Count(salesman.CompanyCode) > 1 && String.IsNullOrEmpty(salesman.Code))
     {
         throw new InvalidException("SIDC is required.");
     }
     if (salesman.Id == null || salesman.Id == 0)
     {
         SalesmanModel existSalesman = _salesman.Get(salesman.CompanyCode, salesman.Code).FirstOrDefault();
         if (existSalesman == null)
         {
             return(_salesman.Add(salesman));
         }
         else
         {
             throw new InvalidException($"{salesman.Code} already exist, try with another code.");
         }
     }
     else
     {
         return(_salesman.Update(salesman));
     }
 }
 public Employee Add(Employee employee)
 {
     return(Employee.Add(employee));
 }
Exemplo n.º 18
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int  Add(Library.Model.Employee model)
 {
     return(dal.Add(model));
 }
Exemplo n.º 19
0
        public async Task <IActionResult> Add([FromBody] Employee record)
        {
            var newRecord = await _employeeService.Add(record);

            return(Ok(newRecord));
        }
Exemplo n.º 20
0
 public IHttpActionResult Post([FromBody] Employee employee)
 {
     iEmployee.Add(employee);
     return(Ok());
 }