public ActionResult Edit(int id = 0)
 {
     var entity = _activityRepository.Entities.SingleOrDefault(x => x.ID == id);
     if (entity == null)
     {
         entity = new Activity();
     }
     if (id == 0)
     {
         entity.StartDate = DateTime.Now;
         entity.FinishDate = DateTime.Now.AddHours(2);
     }
     var viewModel = new ActivityViewModel();
     viewModel.Activity = entity;
     return View(viewModel);
 }
        public ActionResult Edit(ActivityViewModel model)
        {
            Activity entity = model.Activity;
            entity.UserID = 1;
            if (model.ID == 0)
            {
                try
                {
                    /*if (entity.StatusID == 0)
                    {
                        entity.StatusID = 1;
                    }*/
                    if (_activityRepository.Add(entity))
                    {
                        return RedirectToAction("Grid", "ActivityGrid");
                    }
                }
                catch (Exception ex)
                {
                    ViewBag.ErrorMessage = ex.Message;
                    return View(model);
                }
            }
            else
            {
                try
                {
                    if (string.IsNullOrEmpty(entity.Name))
                    {
                        entity.Name = string.Empty;
                    }
                    if (_activityRepository.Update(entity))
                    {
                        return RedirectToAction("Grid", "ActivityGrid");
                    }
                }
                catch (Exception ex)
                {
                    ViewBag.ErrorMessage = ex.Message;
                    return View(model);
                }
            }

            ViewBag.ErrorMessage = "Не удалось сохранить запись";
            return View(model);
        }