Пример #1
0
        public ActionResult Create(SummaryModel summary)
        {
            if (!String.IsNullOrWhiteSpace(summary.Title))
            {
                if (summary.Id > 0)
                {
                    _serviceAdapter.UpdateSummary(summary.Id, summary.Title, summary.Activities);
                }
                else
                {
                    _serviceAdapter.CreateSummary(summary.Title, summary.Activities);

                }
            }
            else
            {
                ModelState.AddModelError("", "Укажите название отчета.");
            }
            return RedirectToAction("Index");
        }
Пример #2
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            const string activityString = "Activity";
            NameValueCollection form = controllerContext.HttpContext.Request.Form;
            SummaryModel model = new SummaryModel();

            model.Title = form["Title"];
            model.Id = 0;
              int modelId;
              if(Int32.TryParse(form["summaryId"], out modelId))
              {
            model.Id = modelId;
              }

              string[] activities = form.AllKeys.Where(x => x.StartsWith(activityString, StringComparison.OrdinalIgnoreCase)).ToArray();
            model.Activities = new int[activities.Count()];
            for (int i = 0; i < activities.Count(); i++)
            {
                model.Activities[i] = Int32.Parse(activities[i].Replace(activityString, ""));
            }

            return model;
        }