Пример #1
0
        public async Task <ActionResult> Create(LeaveTypeViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    throw new Exception("Model State is not Valid!");
                }

                var entity = mapper.Map <LeaveType>(model);
                if (!await repo.CreateAsync(entity).ConfigureAwait(false))
                {
                    throw new Exception("Creation has failed!");
                }

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                ModelState.TryAddModelException(nameof(ex.Message), ex);
                return(View());
            }
        }