//GET
        public ActionResult Edit(int id)
        {
            ViewBag.Countries = new SelectList(_countryManager.GetAll().ToList(), "Id", "Name");
            var dbItem = _manufacturerManager.GetById(id);

            if (dbItem == null)
            {
                throw new NullReferenceException();
            }
            return(View(_manufacturerFieldCopier.CopyFields(dbItem, new ManufacturerViewModel())));
        }
Beispiel #2
0
        // GET: Manufacturers/Details/5
        public ActionResult Details(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Manufacturer manufacturer = _manufacturerManager.GetById((long)id);

            if (manufacturer == null)
            {
                return(HttpNotFound());
            }
            return(View(manufacturer));
        }
Beispiel #3
0
        public JsonResult GetManufacturerById(int?id)
        {
            Manufacturer manufacturer = null;

            if (id != null)
            {
                manufacturer = _manufacturerManager.GetById((int)id);
            }

            return(Json(manufacturer, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Delete(int id)
        {
            var manufacturer = _manufacturerManager.GetById(id);

            try
            {
                if (_manufacturerManager.Remove(manufacturer))
                {
                    ViewBag.Msg = "Deleted successfully!";

                    return(View("Search"));
                }
            }
            catch (Exception exception)
            {
                //return HttpNotFound();
                ViewBag.Msg = exception.GetType().ToString();
            }

            return(View("Search"));
        }
Beispiel #5
0
        public ActionResult CreateCar(CarItemViewModel model, List <HttpPostedFileBase> files)
        {
            var userId = User.Identity.GetUserId();

            if (!ModelState.IsValid)
            {
                return(View("Create", model));
            }
            var dbItem = _carItemFieldCopier.CopyFields(model, new CarItem());

            SaveImagesAndLink(dbItem, files);

            dbItem.OwnerId      = userId;
            dbItem.LastEditorId = userId;
            dbItem.EditDate     = DateTime.Now;
            dbItem.Status       = (int)CarItemStatus.Open;

            //add new car into db
            _carItemManager.Add(dbItem);
            //notify all users
            var sb = new StringBuilder();

            if (dbItem.ModelId != null)
            {
                dbItem.CarModel = _carModelManager.GetById((int)dbItem.ModelId);
            }
            if (dbItem.BodyTypeId != null)
            {
                dbItem.CarBodyType = _carBodyTypeManager.GetById((int)dbItem.BodyTypeId);
            }
            if (dbItem.ModelId != null && dbItem.CarModel?.ManufacturerId != null)
            {
                dbItem.CarModel.Manufacturer = _manufacturerManager.GetById((int)dbItem.CarModel.ManufacturerId);
            }
            sb.AppendFormat($"Added : {dbItem.CarModel?.Manufacturer?.Name}");
            sb.AppendFormat($" {dbItem.CarModel?.Name}");
            sb.AppendFormat($" {dbItem.CarBodyType?.Name}");
            sb.AppendFormat($" {dbItem.ReleaseYear}r.y.");
            sb.AppendFormat($" {dbItem.Price}$");
            NotificationsHub.SendInfoMessage(sb.ToString());
            return(RedirectToAction("List"));
        }