public ActionResult Create(Equipment equipment)
 {
     if (!ModelState.IsValid)
     {
         var viewModel = new EquipmentFormViewModel
         {
             Equipment     = equipment,
             Manufacturers = _context.Manufacturers.ToList()
         };
         return(View("EquipmentForm", viewModel));
     }
     if (equipment.Id == 0)
     {
         _context.Equipments.Add(equipment);
     }
     else
     {
         var existingEquipment = _context.Equipments.Single(e => e.Id == equipment.Id);
         existingEquipment.Kind           = equipment.Kind;
         existingEquipment.Description    = equipment.Description;
         existingEquipment.InStock        = equipment.InStock;
         existingEquipment.ManufacturerId = equipment.ManufacturerId;
     }
     _context.SaveChanges();
     return(RedirectToAction("Index", "Equipment"));
 }
Ejemplo n.º 2
0
        public ActionResult Save(Equipment equipment)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new EquipmentFormViewModel
                {
                    Equipment = equipment,
                    Models    = _context.ModelTypes.ToList()
                };

                return(View("EquipmentForm", viewModel));
            }


            if (equipment.Id == 0)
            {
                _context.Equipment.Add(equipment);
            }
            else
            {
                var equipmentInDb = _context.Equipment.Single(e => e.Id == equipment.Id);
                equipmentInDb.Name            = equipment.Name;
                equipmentInDb.ModelType       = equipment.ModelType;
                equipmentInDb.ManufactureDate = equipment.ManufactureDate;
                equipmentInDb.PurchaseDate    = equipment.PurchaseDate;
                equipmentInDb.Stock           = equipment.Stock;
            }

            _context.SaveChanges();

            return(RedirectToAction("Index", "Equipment"));
        }
Ejemplo n.º 3
0
        public ActionResult Save(Equipment equipment)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new EquipmentFormViewModel()
                {
                    Equipment   = equipment,
                    RentalTypes = _context.RentalTypes.ToList()
                };

                return(View("EquipmentForm", viewModel));
            }

            if (equipment.Id == 0)
            {
                _context.Equipments.Add(equipment);
            }
            else
            {
                var equipmentInDb = _context.Equipments.Single(e => e.Id == equipment.Id);

                Mapper.Map(equipment, equipmentInDb);
            }

            _context.SaveChanges();
            return(RedirectToAction("Index", "Equipment"));
        }
Ejemplo n.º 4
0
        public ActionResult Save(Equipment equipment)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new EquipmentFormViewModel(equipment)
                {
                    Category = _context.Category.ToList()
                };
                return(View("EquipmentForm", viewModel));
            }
            if (equipment.Id == 0)
            {
                equipment.DateAdded = DateTime.Now;
                _context.Equipments.Add(equipment);
            }
            else
            {
                var equipmentInDb = _context.Equipments.Single(mbox => mbox.Id == equipment.Id);

                equipmentInDb.Name          = equipment.Name;
                equipmentInDb.CategoryId    = equipment.CategoryId;
                equipmentInDb.NumberInStock = equipment.NumberInStock;
            }

            _context.SaveChanges();

            return(RedirectToAction("Index", "Equipments"));
        }
Ejemplo n.º 5
0
        public ViewResult New()
        {
            var category = _context.Category.ToList();

            var viewModel = new EquipmentFormViewModel
            {
                Category = category
            };

            return(View("EquipmentForm", viewModel));
        }
        public ActionResult New()
        {
            var manufacturers = _context.Manufacturers.ToList();
            var viewModel     = new EquipmentFormViewModel
            {
                Equipment     = new Equipment(),
                Manufacturers = manufacturers
            };

            return(View("EquipmentForm", viewModel));
        }
Ejemplo n.º 7
0
        public ActionResult New()
        {
            var rentalType = _context.RentalTypes.ToList();
            var viewModel  = new EquipmentFormViewModel()
            {
                Equipment   = new Equipment(),
                RentalTypes = rentalType
            };

            return(View("EquipmentForm", viewModel));
        }
Ejemplo n.º 8
0
        public ActionResult New()
        {
            var modelTypes = _context.ModelTypes.ToList();

            var viewModel = new EquipmentFormViewModel
            {
                Equipment = new Equipment(),
                Models    = modelTypes
            };

            ViewBag.PageTitle = "New";

            return(View("EquipmentForm", viewModel));
        }
        public ActionResult Edit(int id)
        {
            var equipment = _context.Equipments.SingleOrDefault(e => e.Id == id);

            if (equipment == null)
            {
                return(HttpNotFound());
            }
            var viewModel = new EquipmentFormViewModel
            {
                Equipment     = equipment,
                Manufacturers = _context.Manufacturers.ToList()
            };

            return(View("EquipmentForm", viewModel));
        }
Ejemplo n.º 10
0
        public ActionResult Edit(int id)
        {
            var equipment = _context.Equipments.SingleOrDefault(c => c.Id == id);

            if (equipment == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new EquipmentFormViewModel(equipment) // face legatura cu equipmentformviewmodel - public equipmentformviewmodel; ca sa fie codu mai clar
            {
                Category = _context.Category.ToList()
            };

            return(View("EquipmentForm", viewModel));
        }
Ejemplo n.º 11
0
        public ActionResult Edit(int id)
        {
            var equipment = _context.Equipment.SingleOrDefault(c => c.Id == id);

            if (equipment == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new EquipmentFormViewModel
            {
                Equipment = equipment,
                Category  = _context.Category.ToList()
            };

            return(View("EquipmentForm", viewModel));
        }
Ejemplo n.º 12
0
        public ActionResult Edit(int id)
        {
            var equipment = _context.Equipment.SingleOrDefault(e => e.Id == id);

            if (equipment == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new EquipmentFormViewModel
            {
                Equipment = equipment,
                Models    = _context.ModelTypes.ToList(),
            };

            ViewBag.PageTitle = "Edit";

            return(View("EquipmentForm", viewModel));
        }