public ActionResult Create([Bind(Include = "Id,Name")] VehicleTypeViewModel vehicleTypeViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    VehicleType vehicleType = Mapper.Map <VehicleType>(vehicleTypeViewModel);

                    var name = vehicleType.Name.Trim();
                    if (_vehicleTypeManager.GetAll().Count(o => o.Name == name) > 0)
                    {
                        ViewBag.Message = "Vehicle type name already exist.";
                    }
                    if (ViewBag.Message == null)
                    {
                        _vehicleTypeManager.Add(vehicleType);
                        TempData["msg"] = "Information has been saved successfully";
                        return(RedirectToAction("Index"));
                    }
                }

                return(View(vehicleTypeViewModel));
            }
            catch (Exception ex)
            {
                ExceptionMessage(ex);
                return(View("Error", new HandleErrorInfo(ex, "VehicleTypes", "Create")));
            }
        }
Exemplo n.º 2
0
        public ActionResult Create(VehicleTypeViewModel collection)
        {
            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    var vehicletype = _mapper.Map <VehicleType>(collection);
                    var IsSuccess   = _vehicleTypeManager.Add(vehicletype);
                    if (IsSuccess)
                    {
                        return(RedirectToAction("Index"));
                    }
                    return(NotFound());
                }



                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Exemplo n.º 3
0
        public ActionResult Create([Bind(Include = "Id,TypeName,Description")] VehicleTypeViewModel vehicleTypeViewModel)
        {
            if (ModelState.IsValid)
            {
                VehicleType vehicleType = Mapper.Map <VehicleType>(vehicleTypeViewModel);
                _vehicleTypeManager.Add(vehicleType);

                TempData["Message"] = "Vehicle Type info save successfully!";
                return(RedirectToAction("Index"));
            }

            return(View(vehicleTypeViewModel));
        }
Exemplo n.º 4
0
 public ActionResult Create(VehicleTypeViewModel vehicleTypeVM)
 {
     try
     {
         VehicleType vehicleType = new VehicleType();
         vehicleType.TypeName = vehicleTypeVM.TypeName;
         bool isSaved = _typeManager.Add(vehicleType);
         if (isSaved)
         {
             TempData["msg"] = "Vehicle Type Saved Successfully";
         }
         return(RedirectToAction("Create"));
     }
     catch
     {
         return(View());
     }
 }