Esempio n. 1
0
        public ActionResult Create(TaskViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (model.StartDate > model.EndDate)
                    {
                        ModelState.AddModelError("StartDate", "Start date cannot be later than end date of the task");
                        return(View(model));
                    }

                    var task = TaskMapper.MapViewModelToItem(model);
                    task.created = DateTime.Today;
                    unitOfWork.TasksRepository.Insert(task);
                    unitOfWork.Save();
                    return(RedirectToAction("Index"));
                }
            }
            catch (DataException dex)
            {
                ModelState.AddModelError("", dex.Message);
            }
            return(View(model));
        }