public ActionResult Create(EmployeeWageRateVM model)
        {
            try
            {
                // TODO: Adding insert logic here
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                var empWageRate = _mapper.Map <EmployeeWageRate>(model);
                empWageRate.DateCreated = DateTime.Now;

                var isSuccess = _repo.Create(empWageRate);
                if (!isSuccess)
                {
                    ModelState.AddModelError("", "There is a fault somewhere...");
                    return(View(model));
                }

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                ModelState.AddModelError("", "There is a fault somewhere...");
                return(View(model));
            }
        }
        public ActionResult Delete(int id, EmployeeWageRateVM model)
        {
            try
            {
                // TODO: Adding delete logic here
                var empWageRate = _repo.FindById(id);

                if (empWageRate == null)
                {
                    return(NotFound());
                }

                var isSuccess = _repo.Delete(empWageRate);

                if (!isSuccess)
                {
                    return(View(model));
                }
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View(model));
            }
        }
Пример #3
0
        // Creating a custom action
        public ActionResult SetWage(int id)
        {
            var empjobinfo = _empjobinforepo.FindById(id);
            var employees  = _userManager.GetUsersInRoleAsync("Employee").Result;

            foreach (var emp in employees)
            {
                if (_empwagesrepo.CheckAllocation(id, emp.Id))
                {
                    continue;
                }

                var allocation = new EmployeeWageRateVM
                {
                    DateCreated       = DateTime.Now,
                    EmployeeId        = emp.Id,
                    EmployeeTypeId    = id,
                    MonthlyIncome     = int.MaxValue,
                    DailyRate         = int.MaxValue,
                    HourlyRate        = int.MaxValue,
                    Overtime          = string.Empty,
                    PercentSalaryHike = int.MaxValue,
                    Period            = DateTime.Now.Year,
                };
                var empwages = _mapper.Map <EmployeeWageRate>(allocation);
                _empwagesrepo.Create(empwages);
            }
            return(RedirectToAction(nameof(Index)));
        }
 public ActionResult Edit(EmployeeWageRateVM model)
 {
     try
     {
         // TODO: Adding update logic here
         if (!ModelState.IsValid)                // Validating the data
         {
             return(View(model));
         }
         var empWageRate = _mapper.Map <EmployeeWageRate>(model);           // Mapping from ViewModel to Data class and storing in variable
         var isSuccess   = _repo.Update(empWageRate);
         if (!isSuccess)
         {
             ModelState.AddModelError("", "There is a fault somewhere...");
             return(View(model));
         }
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         ModelState.AddModelError("", "There is a fault somewhere...");
         return(View(model));
     }
 }