Beispiel #1
0
        public IHttpActionResult Search(string view, string quickSearch, int?minPrice, int?maxPrice, int?minYear, int?maxYear)
        {
            //check model state befor try
            _listingManager = ListingManagerFactory.Create();

            try
            {
                var parameters = new ListingSearchParameters()
                {
                    View        = view,
                    QuickSearch = quickSearch,
                    MinPrice    = minPrice,
                    MaxPrice    = maxPrice,
                    MinYear     = minYear,
                    MaxYear     = maxYear
                };

                var result = _listingManager.Search(parameters);
                return(Ok(result.Payload));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public ActionResult Index()
        {
            //get managers
            ListingManager listingManager = ListingManagerFactory.Create();
            SpecialManager specialManager = SpecialManagerFactory.Create();

            //get responses
            ListingFeaturedResponse listingFeaturedResponse = listingManager.GetFeaturedListings();
            SpecialGetAllResponse   specialResponse         = specialManager.GetAllSpecials();

            //validate responses
            if (!listingFeaturedResponse.Success || !specialResponse.Success)
            {
                return(new HttpStatusCodeResult(500, $"Error in cloud. Message:{listingFeaturedResponse.Message} {specialResponse.Message}"));
            }
            else
            {
                //build vm
                HomeVM model = new HomeVM();

                model.SetFeaturedListingItems(listingFeaturedResponse.Listings);
                model.SetSpecialItems(specialResponse.Specials);

                return(View(model));
            }
        }
Beispiel #3
0
        public ActionResult Purchase(PurchaseListingVM model)
        {
            _purchaseManager = PurchaseManagerFactory.Create();
            _stateManager    = StateManagerFactory.Create();
            _listingManager  = ListingManagerFactory.Create();

            try
            {
                var listingResponse = _listingManager.GetListingById(model.ListingToPurchase.ListingId);

                model.ListingToPurchase = listingResponse.Payload;

                if (ModelState.IsValid)
                {
                    //set sold listing in db


                    //set user name
                    model.PurchaseForm.UserName = User.Identity.Name;

                    //set listing id
                    model.PurchaseForm.ListingId = model.ListingToPurchase.ListingId;

                    //set date
                    model.PurchaseForm.DateAdded = DateTime.Now;



                    //send to manager
                    var response = _purchaseManager.SavePurchase(model.PurchaseForm);

                    if (!response.Success)
                    {
                        return(new HttpStatusCodeResult(500, $"Error in cloud. Message:{response.Message}"));
                    }
                }
                else
                {
                    var stateResponse = _stateManager.GetAllStates();

                    model.States = stateResponse.Payload.Select(m => new SelectListItem
                    {
                        Text  = m.StateAbbreviation,
                        Value = m.StateId.ToString()
                    });


                    return(View(model));
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Something wrong happened while loading a purchase:", ex);
            }
        }
Beispiel #4
0
        public IHttpActionResult GetUsedInventoryReport(string report)
        {
            _listingManager = ListingManagerFactory.Create();

            try
            {
                var result = _listingManager.GetInventoryReport(report);
                return(Ok(result.Payload));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public ActionResult DeleteListing(int listingId)
        {
            _listingManager = ListingManagerFactory.Create();

            var response = _listingManager.DeleteListing(listingId);

            if (response.Success)
            {
                return(RedirectToAction("Vehicles"));
            }
            else
            {
                return(new HttpStatusCodeResult(500, $"Error in cloud. Message:{response.Message}"));
            }
        }
        public ActionResult Details(int id)
        {
            _listingManager = ListingManagerFactory.Create();

            var response = _listingManager.GetListingById(id);

            if (!response.Success)
            {
                return(new HttpStatusCodeResult(500, $"Error in cloud. Message:{response.Message}"));
            }
            else
            {
                var model = new ListingVM();
                model.Listing = response.Payload;

                return(View(model));
            }
        }
Beispiel #7
0
        public ActionResult Purchase(int id)
        {
            try
            {
                _listingManager = ListingManagerFactory.Create();
                _stateManager   = StateManagerFactory.Create();

                var listingResponse = _listingManager.GetListingById(id);

                if (!listingResponse.Success)
                {
                    return(new HttpStatusCodeResult(500, $"Error in cloud. Message:{listingResponse.Message}"));
                }
                else
                {
                    var model = new PurchaseListingVM
                    {
                        ListingToPurchase = listingResponse.Payload,
                        PurchaseForm      = new Purchase()
                    };

                    var stateResponse = _stateManager.GetAllStates();

                    model.States = stateResponse.Payload.Select(m => new SelectListItem
                    {
                        Text  = m.StateAbbreviation,
                        Value = m.StateId.ToString()
                    });

                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Something wrong happened while loading a purchase:", ex);
            }
        }
        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));
                }
            }
        }
        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));
            }
        }