示例#1
0
        public ActionResult Makes(MakesVM model)
        {
            _makeManager = MakeManagerFactory.Create();

            if (ModelState.IsValid)
            {
                try
                {
                    model.NewMake.DateAdded = DateTime.Now;
                    model.NewMake.UserName  = User.Identity.Name;

                    var response = _makeManager.SaveMake(model.NewMake);

                    if (!response.Success)
                    {
                        return(new HttpStatusCodeResult(500, $"Error in cloud. Message:{response.Message}"));
                    }

                    return(RedirectToAction("Makes"));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                var response = _makeManager.GetAllMakes();
                model.SetMakeItems(response.Payload);

                return(View(model));
            }
        }
示例#2
0
        public ActionResult Models()
        {
            _modelManager = ModelManagerFactory.Create();
            _makeManager  = MakeManagerFactory.Create();

            var model         = new ModelsVM();
            var modelResponse = _modelManager.GetAllModels();
            var makeResponse  = _makeManager.GetAllMakes();

            if (!modelResponse.Success || !makeResponse.Success)
            {
                return(new HttpStatusCodeResult(500, $"Error in cloud. Message:{modelResponse.Message} {makeResponse.Message}"));
            }
            else
            {
                model.SetModelItems(modelResponse.Payload);

                model.Makes = makeResponse.Payload.Select(m => new SelectListItem
                {
                    Text  = m.MakeName,
                    Value = m.MakeId.ToString()
                });

                return(View(model));
            }
        }
示例#3
0
        public ActionResult Makes()
        {
            _makeManager = MakeManagerFactory.Create();
            var model    = new MakesVM();
            var response = _makeManager.GetAllMakes();

            if (!response.Success)
            {
                return(new HttpStatusCodeResult(500, $"Error in cloud. Message:{response.Message}"));
            }
            else
            {
                model.SetMakeItems(response.Payload);
                return(View(model));
            }
        }
示例#4
0
        public ActionResult Models(ModelsVM model)
        {
            _modelManager = ModelManagerFactory.Create();
            _makeManager  = MakeManagerFactory.Create();

            if (ModelState.IsValid)
            {
                model.NewModel.DateAdded = DateTime.Now;
                model.NewModel.UserName  = User.Identity.Name;

                //save
                var response = _modelManager.SaveModel(model.NewModel);

                //throw error for non success
                if (!response.Success)
                {
                    return(new HttpStatusCodeResult(500, $"Error in cloud. Message:{response.Message}"));
                }

                return(RedirectToAction("Models"));
            }
            else
            {
                var modelResponse = _modelManager.GetAllModels();
                var makeResponse  = _makeManager.GetAllMakes();
                model.SetModelItems(modelResponse.Payload);

                model.Makes = makeResponse.Payload.Select(m => new SelectListItem
                {
                    Text  = m.MakeName,
                    Value = m.MakeId.ToString()
                });

                return(View(model));
            }
        }
示例#5
0
        public ActionResult AddVehicle()
        {
            _makeManager          = MakeManagerFactory.Create();
            _modelManager         = ModelManagerFactory.Create();
            _interiorColorManager = InteriorColorManagerFactory.Create();
            _exteriorColorManager = ExteriorColorManagerFactory.Create();
            _bodyStyleManager     = BodyStyleManagerFactory.Create();

            try
            {
                var model = new AddListingVM();

                //load all the items
                var modelResponse    = _modelManager.GetAllModels();
                var makeResponse     = _makeManager.GetAllMakes();
                var interiorResponse = _interiorColorManager.GetAll();
                var exteriorReponse  = _exteriorColorManager.GetAll();
                var bodyResponse     = _bodyStyleManager.GetAll();

                //verify they all loaded
                if (!modelResponse.Success ||
                    !makeResponse.Success ||
                    !interiorResponse.Success ||
                    !exteriorReponse.Success ||
                    !bodyResponse.Success)
                {
                    return(new HttpStatusCodeResult(500, $"Error in cloud. Message:" +
                                                    $"{modelResponse.Message} " +
                                                    $"{makeResponse.Message}" +
                                                    $"{interiorResponse.Message}" +
                                                    $"{exteriorReponse.Message}" +
                                                    $"{bodyResponse.Message}"));
                }
                else
                {
                    //create select list items
                    model.Makes = makeResponse.Payload.Select(m => new SelectListItem
                    {
                        Text  = m.MakeName,
                        Value = m.MakeId.ToString()
                    });

                    model.Models = modelResponse.Payload.Select(m => new SelectListItem
                    {
                        Text  = m.ModelName,
                        Value = m.ModelId.ToString()
                    });

                    model.ExteriorColors = exteriorReponse.Payload.Select(m => new SelectListItem
                    {
                        Text  = m.ExteriorColorName,
                        Value = m.ExteriorColorId.ToString()
                    });

                    model.InteriorColors = interiorResponse.Payload.Select(m => new SelectListItem
                    {
                        Text  = m.InteriorColorName,
                        Value = m.InteriorColorId.ToString()
                    });

                    model.BodyStyles = bodyResponse.Payload.Select(m => new SelectListItem
                    {
                        Text  = m.BodyStyleName,
                        Value = m.BodyStyleId.ToString()
                    });

                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Something wrong happened loading the add screen:", ex);
            }
        }
示例#6
0
        public ActionResult EditVehicle(EditListingVM model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _listingManager = ListingManagerFactory.Create();

                    var oldListingResponse = _listingManager.GetListingById(model.Listing.ListingId);

                    if (model.ImageUpload != null && model.ImageUpload.ContentLength > 0)
                    {
                        var savepath = Server.MapPath("~/Images/");

                        string fileName  = Path.GetFileNameWithoutExtension(model.ImageUpload.FileName);
                        string extension = Path.GetExtension(model.ImageUpload.FileName);

                        var filePath = Path.Combine(savepath, fileName + extension);

                        int counter = 1;
                        while (System.IO.File.Exists(filePath))
                        {
                            filePath = Path.Combine(savepath, fileName + counter.ToString() + extension);
                            counter++;
                        }

                        model.ImageUpload.SaveAs(filePath);
                        model.Listing.ImageFileUrl = Path.GetFileName(filePath);

                        //delete the old file, use the response to get it
                        var oldPath = Path.Combine(savepath, oldListingResponse.Payload.ImageFileUrl);
                        if (System.IO.File.Exists(oldPath))
                        {
                            System.IO.File.Delete(oldPath);
                        }
                    }
                    else
                    {
                        model.Listing.ImageFileUrl = oldListingResponse.Payload.ImageFileUrl;
                    }

                    var listingResponse = _listingManager.UpdateListing(model.Listing);

                    if (listingResponse.Success)
                    {
                        return(RedirectToAction("Vehicles"));
                        //return RedirectToAction("EditVehicle", new { id = listingResponse.Payload.ListingId });
                    }
                    else
                    {
                        return(new HttpStatusCodeResult(500, $"Error in cloud. Message:" +
                                                        $"{listingResponse.Message}"));
                    }
                }
                catch (Exception ex)
                {
                    throw new ApplicationException("Something wrong happened while trying to edit a listing:", ex);
                }
            }
            else
            {
                //reset page with items
                _makeManager          = MakeManagerFactory.Create();
                _modelManager         = ModelManagerFactory.Create();
                _interiorColorManager = InteriorColorManagerFactory.Create();
                _exteriorColorManager = ExteriorColorManagerFactory.Create();
                _bodyStyleManager     = BodyStyleManagerFactory.Create();
                _listingManager       = ListingManagerFactory.Create();

                //load all the items
                var modelResponse    = _modelManager.GetAllModels();
                var makeResponse     = _makeManager.GetAllMakes();
                var interiorResponse = _interiorColorManager.GetAll();
                var exteriorReponse  = _exteriorColorManager.GetAll();
                var bodyResponse     = _bodyStyleManager.GetAll();

                //verify they all loaded
                if (!modelResponse.Success ||
                    !makeResponse.Success ||
                    !interiorResponse.Success ||
                    !exteriorReponse.Success ||
                    !bodyResponse.Success)
                {
                    return(new HttpStatusCodeResult(500, $"Error in cloud. Message:" +
                                                    $"{modelResponse.Message} " +
                                                    $"{makeResponse.Message}" +
                                                    $"{interiorResponse.Message}" +
                                                    $"{exteriorReponse.Message}" +
                                                    $"{bodyResponse.Message}"));
                }
                else
                {
                    //create select list items
                    model.Makes = makeResponse.Payload.Select(m => new SelectListItem
                    {
                        Text  = m.MakeName,
                        Value = m.MakeId.ToString()
                    });

                    model.Models = modelResponse.Payload.Select(m => new SelectListItem
                    {
                        Text  = m.ModelName,
                        Value = m.ModelId.ToString()
                    });

                    model.ExteriorColors = exteriorReponse.Payload.Select(m => new SelectListItem
                    {
                        Text  = m.ExteriorColorName,
                        Value = m.ExteriorColorId.ToString()
                    });

                    model.InteriorColors = interiorResponse.Payload.Select(m => new SelectListItem
                    {
                        Text  = m.InteriorColorName,
                        Value = m.InteriorColorId.ToString()
                    });

                    model.BodyStyles = bodyResponse.Payload.Select(m => new SelectListItem
                    {
                        Text  = m.BodyStyleName,
                        Value = m.BodyStyleId.ToString()
                    });

                    return(View(model));
                }
            }
        }
示例#7
0
        public ActionResult EditVehicle(int id)
        {
            var model = new EditListingVM();

            //reset page with items
            _makeManager          = MakeManagerFactory.Create();
            _modelManager         = ModelManagerFactory.Create();
            _interiorColorManager = InteriorColorManagerFactory.Create();
            _exteriorColorManager = ExteriorColorManagerFactory.Create();
            _bodyStyleManager     = BodyStyleManagerFactory.Create();
            _listingManager       = ListingManagerFactory.Create();

            //load all the items
            var modelResponse    = _modelManager.GetAllModels();
            var makeResponse     = _makeManager.GetAllMakes();
            var interiorResponse = _interiorColorManager.GetAll();
            var exteriorReponse  = _exteriorColorManager.GetAll();
            var bodyResponse     = _bodyStyleManager.GetAll();

            //get listing
            var listingResponse = _listingManager.GetListingById(id);


            //verify they all loaded
            if (!modelResponse.Success ||
                !makeResponse.Success ||
                !interiorResponse.Success ||
                !exteriorReponse.Success ||
                !bodyResponse.Success ||
                !listingResponse.Success)
            {
                return(new HttpStatusCodeResult(500, $"Error in cloud. Message:" +
                                                $"{modelResponse.Message} " +
                                                $"{makeResponse.Message}" +
                                                $"{interiorResponse.Message}" +
                                                $"{exteriorReponse.Message}" +
                                                $"{bodyResponse.Message}" +
                                                $"{listingResponse.Message}"));
            }
            else
            {
                //create select list items
                model.Makes = makeResponse.Payload.Select(m => new SelectListItem
                {
                    Text  = m.MakeName,
                    Value = m.MakeId.ToString()
                });

                model.Models = modelResponse.Payload.Select(m => new SelectListItem
                {
                    Text  = m.ModelName,
                    Value = m.ModelId.ToString()
                });

                model.ExteriorColors = exteriorReponse.Payload.Select(m => new SelectListItem
                {
                    Text  = m.ExteriorColorName,
                    Value = m.ExteriorColorId.ToString()
                });

                model.InteriorColors = interiorResponse.Payload.Select(m => new SelectListItem
                {
                    Text  = m.InteriorColorName,
                    Value = m.InteriorColorId.ToString()
                });

                model.BodyStyles = bodyResponse.Payload.Select(m => new SelectListItem
                {
                    Text  = m.BodyStyleName,
                    Value = m.BodyStyleId.ToString()
                });

                model.Listing = listingResponse.Payload;

                return(View(model));
            }
        }