Ejemplo n.º 1
0
        public async Task <ActionResult> Create(VacationTypeVM model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                var vacationType = _mapper.Map <VacationType>(model);
                vacationType.DateCreated = DateTime.Now;
                var isSuccess = await _repo.Create(vacationType);

                if (!isSuccess)
                {
                    ModelState.AddModelError("", "Something Went Wrong...");
                    return(View(model));
                }

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
        // GET: VacationTypeController/Edit/5
        public ActionResult Edit(int id)
        {
            var            vacationtype = _db.VacationTypes.Find(id);
            VacationTypeVM model        = ReverseMap(vacationtype);

            return(View(model));
        }
        public VacationTypeVM ReverseMap(VacationType vacation)
        {
            VacationTypeVM model = new VacationTypeVM();

            model.Id      = vacation.Id;
            model.Name    = vacation.Name;
            model.Balance = vacation.Balance;
            return(model);
        }
        public VacationType Map(VacationTypeVM model)
        {
            VacationType vacationtype = new VacationType();

            vacationtype.Id      = model.Id;
            vacationtype.Name    = model.Name;
            vacationtype.Balance = model.Balance;
            return(vacationtype);
        }
        public ActionResult Edit(VacationTypeVM model)
        {
            try
            {
                VacationType vacationtype = Map(model);
                _db.VacationTypes.Update(vacationtype);
                _db.SaveChanges();

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception)
            {
                ModelState.AddModelError("", "Something went wrong...");
                return(View(model));
            }
        }
        public ActionResult Create(VacationTypeVM model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                VacationType vacationType = new VacationType();
                vacationType = Map(model);
                _db.VacationTypes.Add(vacationType);
                _db.SaveChanges();

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                ModelState.AddModelError("", "Something went wrong...");
                return(View(model));
            }
        }
Ejemplo n.º 7
0
        public async Task <ActionResult> Delete(int id, VacationTypeVM model)
        {
            try
            {
                var vacationtype = await _repo.FindById(id);

                if (vacationtype == null)
                {
                    return(NotFound());
                }
                var isSuccess = await _repo.Delete(vacationtype);

                if (!isSuccess)
                {
                    ModelState.AddModelError("", "Something Went Wrong...");
                    return(View(model));
                }
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
 public ActionResult Delete(VacationTypeVM model)
 {
     return(View(model));
 }