private Goal MapCreateGoalViewModelToEntity(CreateGoalViewModel model)
 {
     return(new Goal
     {
         Name = model.Name,
         Category = model.Category,
         Progress = model.Progress,
         Description = model.Descirption,
         DueDateTime = model.DueDateTime.Value,
         Duration = model.Duration,
         StartDate = model.StartTime.Value,
     });
 }
        public ActionResult Create(CreateGoalViewModel model)
        {
            try
            {
                _service.Create(MapCreateGoalViewModelToEntity(model));

                TempData["message"] = "A coś tam się stało";
                return(RedirectToAction("Index"));
            }
            catch
            {
                ModelState.AddModelError("", "Jakiś bład z obiektem");
                return(View());
            }
        }
示例#3
0
        public IActionResult Create(CreateGoalViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            int id = Convert.ToInt32(User.Claims.Where(c => c.Type == "Id")
                                     .Select(c => c.Value).SingleOrDefault());

            bool created = logic.Add(id, model.Title, model.Info, model.StartDT, model.EndDT);

            if (!created)
            {
                ModelState.AddModelError("", "Creating of the goal failed.");

                return(View(model));
            }

            return(RedirectToAction("Index"));
        }