Exemple #1
0
        public ActionResult EditService(ServicesAndPartsView model)
        {
            if (ModelState.IsValid)
            {
                using (GarageManagementEntities entities = new GarageManagementEntities())
                {
                    var part = entities.ServicesAndParts.FirstOrDefault(x => x.Id == model.Id);

                    var newPart = new ServicesAndParts()
                    {
                        Name  = model.Name,
                        Price = model.Price
                    };

                    if (model.Id > 0)
                    {
                        part.Name  = model.Name;
                        part.Price = model.Price;
                    }
                    else
                    {
                        entities.ServicesAndParts.Add(newPart);
                    }

                    entities.SaveChanges();

                    return(RedirectToAction("ConfirmServicesAndParts", "Manage"));
                }
            }


            return(View(model));
        }
Exemple #2
0
        public ActionResult EditService(int id)
        {
            var model = new ServicesAndPartsView();

            using (GarageManagementEntities entities = new GarageManagementEntities())
            {
                var part = entities.ServicesAndParts.FirstOrDefault(x => x.Id == id);
                if (part != null)
                {
                    model = new ServicesAndPartsView()
                    {
                        Name  = part.Name,
                        Price = part.Price.Value,
                        Id    = part.Id,
                    };
                }
            }

            return(View(model));
        }