Ejemplo n.º 1
0
        public ActionResult Edit(NailDesignRequestModel request)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var model = db.NailDesigns.Find(request.Id);

                    model.Name    = request.Name;
                    model.TimeOut = TimeUtils.TimeToUt(request.TimeOut);
                    model.Price   = request.Price;

                    var ndt = db.NailDesignTypes.Where(i => request.NailDesignTypesGuids.Contains(i.Id)).ToList();
                    model.NailDesignTypes.Clear();
                    for (var i = ndt.Count - 1; i >= 0; i--)
                    {
                        model.NailDesignTypes.Add(ndt[i]);
                    }

                    db.SaveChanges();

                    return(RedirectToAction("List"));
                }
                catch (Exception exc)
                {
                    Console.WriteLine(exc);
                }
            }

            InitFilds();

            return(PartialView(request));
        }
Ejemplo n.º 2
0
        public ActionResult Create(NailDesignRequestModel request)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var model = new NailDesign
                    {
                        Id       = request.Id,
                        Name     = request.Name,
                        TimeOut  = TimeUtils.TimeToUt(request.TimeOut),
                        Price    = request.Price,
                        IsActive = true
                    };

                    if (request.NailDesignTypesGuids != null)
                    {
                        var ndt = db.NailDesignTypes.Where(i => request.NailDesignTypesGuids.Contains(i.Id)).ToList();

                        for (var i = ndt.Count - 1; i >= 0; i--)
                        {
                            model.NailDesignTypes.Add(ndt[i]);
                        }
                    }

                    db.NailDesigns.Add(model);

                    db.SaveChanges();

                    return(RedirectToAction("List"));
                }
                catch (Exception exc)
                {
                    ModelState.AddModelError("", "Что то пошло не так.");
                }
            }

            InitFilds();

            return(PartialView(request));
        }