public ActionResult Create(LeaveTypeViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                var leaveType = _mapper.Map <LeaveType>(model);
                leaveType.DateCreated = DateTime.Now;

                if (!_leaveTypeRepo.Add(leaveType))
                {
                    ModelState.AddModelError("", "Something went wrong...");
                    return(View(model));
                }

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                ModelState.AddModelError("", "Something went wrong...");
                return(View(model));
            }
        }
        public bool CreateLeaveType(LeaveType leaveType)
        {
            bool isSuccess = true;

            try
            {
                leaveTypeRepository.Add(leaveType);
                this.SaveRecord();
                ServiceUtil <LeaveType> .WriteActionLog(leaveType.Id, ENUMOperation.CREATE, leaveType);
            }
            catch (Exception ex)
            {
                isSuccess = false;
                logger.Error("Error in creating LeaveType", ex);
            }
            return(isSuccess);
        }
        public ActionResult Create(LeaveTypeVM entity)
        {
            if (entity == null || !ModelState.IsValid)
            {
                return(View(entity));
            }

            try
            {
                entity.DateCreated = DateTime.Now;
                if (!_repository.Add(MapToLeaveType(entity)))
                {
                    ModelState.AddModelError("", "Something went wrong while saving the leave type.");
                    return(View(entity));
                }

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                ModelState.AddModelError("", "Something went wrong while saving the leave type.");
                return(View());
            }
        }
 public IActionResult AddLeaveType([FromBody] LeaveType model)
 {
     LeaveType_repo.Add(model);
     return(new OkObjectResult(new { LeaveTypeID = model.LeaveTypeId }));
 }
Beispiel #5
0
 public void Add(LeaveType entity)
 {
     _leaveTypeRepository.Add(entity);
 }