Beispiel #1
0
        public ActionResult Edit(Guid id, MetaReportModel model, List <MetaReportItemModel> items, string button)
        {
            using (DBEntities context = Settings.CreateDataContext())
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                MetaReport target = null;
                if (model.Id != Guid.Empty)
                {
                    target = MetaReportHelper.Get(model.Id, context);
                    if (target == null)
                    {
                        ModelState.AddModelError("", "Запись не найдена!");
                        return(View(model));
                    }
                }
                else
                {
                    target    = new MetaReport();
                    target.Id = Guid.NewGuid();
                    context.AddToMetaReport(target);
                }

                MetaReportModel.CreateMap();
                Mapper.Map(model, target);

                if (items != null)
                {
                    SyncReportItems(target, items, context);
                }

                try
                {
                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    var sb = new StringBuilder(Resources.Resource.SaveError + ": " + ex.Message);
                    if (ex.InnerException != null)
                    {
                        sb.AppendLine(ex.InnerException.Message);
                    }
                    ModelState.AddModelError("", sb.ToString());
                    return(View(model));
                }

                if (button == "SaveAndExit")
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(RedirectToAction("Edit", new { target.Id }));
                }
            }
        }
Beispiel #2
0
        public ActionResult Edit(Guid?id)
        {
            if (id.HasValue)
            {
                MetaReport obj = MetaReportHelper.Get(id.Value);
                if (obj == null)
                {
                    return(MessageHelper.FormedContentObjectNotFound());
                }

                MetaReportModel.CreateMap();
                MetaReportModel model = Mapper.Map <MetaReport, MetaReportModel>(obj);
                return(View(model));
            }
            else
            {
                return(View(new MetaReportModel()));
            }
        }
Beispiel #3
0
 public static List <MetaReportItemModel> GetItemsForReport(MetaReportModel model)
 {
     return(GetItemsForReport(model.Id));
 }