Exemple #1
0
        public ActionResult Edit(Guid id, MetaSchedulerModel model, string button)
        {
            using (DBEntities context = Settings.CreateDataContext())
            {
                Validate(context, model);

                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

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

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

                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 }));
                }
            }
        }
        public ActionResult Edit(Guid id, MetaSchedulerModel model, string button)
        {
            using (DBEntities context = Settings.CreateDataContext())
            {
                Validate(context, model);

                if (!ModelState.IsValid)
                {
                    return View(model);
                }

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

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

                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});
            }
        }
Exemple #3
0
        public ActionResult Edit(Guid?id)
        {
            if (id.HasValue)
            {
                MetaScheduler obj = MetaSchedulerHelper.Get(id.Value);
                if (obj == null)
                {
                    return(MessageHelper.FormedContentObjectNotFound());
                }

                MetaSchedulerModel.CreateMap();
                MetaSchedulerModel model = Mapper.Map <MetaScheduler, MetaSchedulerModel>(obj);
                return(View(model));
            }
            else
            {
                return(View(new MetaSchedulerModel()));
            }
        }