public IEnumerable <EmployeeViewModel> Post(EmployeeInputViewModel e)
        {
            baseUrl = Request.RequestUri.GetLeftPart(UriPartial.Authority);

            //Upload New File
            if (!string.IsNullOrEmpty(e.ImgFile))
            {
                fileName     = DateTime.Now.ToString("ddMMyyyyHHmmss") + "_" + e.ImageName;
                fileSavePath = HttpContext.Current.Server.MapPath("~/Uploads/Employee/") + fileName;
                Image img = Base64ToImageConvertion(e.ImgFile);
                img.Save(fileSavePath);
                filePath = baseUrl + "/Uploads/Employee/" + fileName;
            }

            Employee emp = new Employee
            {
                ContactNo    = e.ContactNo,
                CreatedOn    = DateTime.Now,
                CreatedBy    = System.Web.HttpContext.Current.User.Identity.GetUserId(),
                UpdatedOn    = DateTime.Now,
                UpdatedBy    = System.Web.HttpContext.Current.User.Identity.GetUserId(),
                Designation  = e.Designation,
                EMailId      = e.EMailId,
                EmployeeName = e.EmployeeName,
                ImagePath    = filePath,
                ManagerID    = e.ManagerID,
                SkillSets    = e.SkillSets
            };

            return(repository.InsertEmployee(emp));
        }
Ejemplo n.º 2
0
        public void ValidTitle()
        {
            var title = new EmployeeInputViewModel();

            title.Title = "Professnional trainer";
            var currentTitle = title.Title;

            Assert.Equal("Professnional trainer", currentTitle);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Insert([FromBody] EmployeeInputViewModel employeeInputViewModel)
        {
            var employeeInputEntity = employeeInputViewModel.ToEntity();
            var employeeEntity      = await employeesService.Insert(employeeInputEntity);

            var employeeViewModel = employeeEntity.ToViewModel();

            return(StatusCode((int)StatusCodes.Status201Created, employeeViewModel));
        }
Ejemplo n.º 4
0
        public void ValidSalary(decimal salary)
        {
            var emplSalary = new EmployeeInputViewModel();

            emplSalary.Salary = salary;

            var result = emplSalary.Salary;

            Assert.True(result >= 0m && result <= 10000m);
        }
Ejemplo n.º 5
0
        // GET: Employees/Create
        public async Task <IActionResult> Create()
        {
            var model = new EmployeeInputViewModel
            {
                JobTitles = new SelectList(this.context.JobTitles, "Id", "Name"),
                Managers  = new SelectList(await this.employeesService.GetManagersSelectList(), "Value", "Text"),
            };

            return(this.View(model));
        }
Ejemplo n.º 6
0
        public async Task DeleteEmployeeAsync(EmployeeInputViewModel employee)
        {
            var currentEmployee = this.repositoryTrainer.All().FirstOrDefault(x => x.Id == employee.Id);

            if (currentEmployee != null)
            {
                this.repositoryTrainer.Delete(currentEmployee);
            }

            await this.repositoryTrainer.SaveChangesAsync();
        }
        public async Task <IActionResult> AddEmployee(EmployeeInputViewModel employee)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(employee));
            }

            await this.adminServices.AddNewEmployeeAsync(employee);

            return(this.Redirect("/AdminPanel/Employees"));
        }
        public IEnumerable <EmployeeViewModel> Put(EmployeeInputViewModel e)
        {
            Employee _existEmp = Get(e.ID);

            baseUrl = Request.RequestUri.GetLeftPart(UriPartial.Authority);


            //If New File Uploaded
            if (!string.IsNullOrEmpty(e.ImgFile))
            {
                if (!string.IsNullOrEmpty(_existEmp.ImagePath))
                {
                    string imagePath = _existEmp.ImagePath.Replace(baseUrl, "");

                    //Delete existing file
                    if (System.IO.File.Exists(HttpContext.Current.Server.MapPath(imagePath)))
                    {
                        System.IO.File.Delete(HttpContext.Current.Server.MapPath(imagePath));
                    }
                }

                fileName     = DateTime.Now.ToString("ddMMyyyyHHmmss") + "_" + e.ImageName;
                fileSavePath = HttpContext.Current.Server.MapPath("~/Uploads/Employee/") + fileName;
                Image img = Base64ToImageConvertion(e.ImgFile);
                img.Save(fileSavePath);
                filePath = baseUrl + "/Uploads/Employee/" + fileName;
            }
            else
            {
                filePath = _existEmp.ImagePath;
            }

            Employee emp = new Employee
            {
                ID           = e.ID,
                ContactNo    = e.ContactNo,
                CreatedOn    = _existEmp.CreatedOn,
                CreatedBy    = _existEmp.CreatedBy,
                UpdatedOn    = DateTime.Now,
                UpdatedBy    = System.Web.HttpContext.Current.User.Identity.GetUserId(),
                Designation  = e.Designation,
                EMailId      = e.EMailId,
                EmployeeName = e.EmployeeName,
                ImagePath    = filePath,
                ManagerID    = e.ManagerID,
                SkillSets    = e.SkillSets
            };

            repository.Detach(_existEmp);

            return(repository.UpdateEmployee(emp));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Create(EmployeeInputViewModel input)
        {
            if (this.ModelState.IsValid)
            {
                this.context.Add(input);
                await this.context.SaveChangesAsync();

                return(this.RedirectToAction(nameof(this.Index)));
            }

            input.JobTitles = new SelectList(this.context.JobTitles, "Id", "Name", input.JobTitleId);
            input.Managers  = new SelectList(await this.employeesService.GetManagersSelectList(), "Value", "Text", input.ManagerId);
            return(this.View(input));
        }
Ejemplo n.º 10
0
        public async Task AddNewEmployeeAsync(EmployeeInputViewModel employee)
        {
            var newEmployee = new Trainer()
            {
                FullName  = employee.Fullname,
                ImageUrl  = employee.ImageUrl,
                Salary    = employee.Salary,
                Title     = employee.Title,
                CreatedOn = DateTime.UtcNow,
            };

            await this.repositoryTrainer.AddAsync(newEmployee);

            await this.repositoryTrainer.SaveChangesAsync();
        }
Ejemplo n.º 11
0
        public static EmployeeInputEntity ToEntity(this EmployeeInputViewModel viewModel)
        {
            if (viewModel == null)
            {
                return(null);
            }

            var entity = new EmployeeInputEntity
            {
                Email = viewModel.Email,
                Name  = viewModel.Name,
            };

            return(entity);
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> DeleteEmployee(string id, EmployeeInputViewModel employee)
        {
            if (id != employee.Id)
            {
                return(this.NotFound());
            }

            if (!this.ModelState.IsValid)
            {
                this.ModelState.AddModelError(string.Empty, "Sorry, but we can't find it this Employee!");
            }

            await this.adminServices.DeleteEmployeeAsync(employee);

            return(this.Redirect("/AdminPanel/Employees"));
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> EditEmployee(string id, EmployeeInputViewModel employee)
        {
            if (id != employee.Id)
            {
                return(this.NotFound());
            }

            if (!this.ModelState.IsValid)
            {
                return(this.View(employee));
            }

            await this.adminServices.EditEmployeeAsync(employee);

            return(this.Redirect("/AdminPanel/Employees"));
        }
 public ActionResult EmployeeAddConfirm(EmployeeInputViewModel evm)
 {
     if (Session["Employee"] == null)
     {
         return(Redirect("/EmployeeLogin/Login"));
     }
     using (var db = new ModelContext())
     {
         if (!ModelState.IsValid)
         {
             return(View("EmployeeAddInput"));
         }
         Employee e = new Employee();
         e.EmpNo    = evm.EmpNo;
         e.EmpName  = evm.EmpName;
         e.Password = evm.Password;
         return(View(e));
     }
 }
Ejemplo n.º 15
0
        public async Task EditEmployeeAsync(EmployeeInputViewModel employee)
        {
            var currentEmployee = this.repositoryTrainer.All().FirstOrDefault(x => x.Id == employee.Id);

            if (currentEmployee != null)
            {
                this.repositoryTrainer.Delete(currentEmployee);

                currentEmployee = new Trainer
                {
                    Id        = employee.Id,
                    FullName  = employee.Fullname,
                    ImageUrl  = employee.ImageUrl,
                    Salary    = employee.Salary,
                    Title     = employee.Title,
                    CreatedOn = DateTime.UtcNow,
                };

                await this.repositoryTrainer.AddAsync(currentEmployee);
            }

            await this.repositoryTrainer.SaveChangesAsync();
        }