Exemple #1
0
 public IHttpActionResult Delete(DealerViewModel pDealer)
 {
     //TODO: Agregar usuario que hizo la acción
     try
     {
         ResponseApiViewModel rta = new ResponseApiViewModel();
         using (DB_FleetServiceEntities db = new DB_FleetServiceEntities())
         {
             var oDealerDB = db.Dealer.Where(dlr => dlr.deal_id == pDealer.id).FirstOrDefault();
             if (oDealerDB != null)
             {
                 oDealerDB.deal_document   = "";
                 oDealerDB.deal_state      = false;
                 oDealerDB.deal_deleteDate = DateTime.Now;
                 db.SaveChanges();
                 rta.response = true;
                 rta.message  = "Se ha eliminado el concesionario: " + oDealerDB.deal_name + " de la base de datos";
                 return(Ok(rta));
             }
             else
             {
                 rta.response = false;
                 rta.message  = "No se encontró el concesionario: " + pDealer.document + " " + pDealer.name + " por lo tanto no se puede eliminar";
                 return(BadRequest(rta.message));
             }
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Exemple #2
0
        public string Generate(DealerViewModel dealer, CarShortViewModel car)
        {
            GeneratePowerPointFromImages(dealer, car);
            if (GenerateVideoFromPowerPoint(dealer, car))
            {
                System.Threading.Thread.Sleep(240000);

                try
                {
                    var video = new YoutubeVideo()
                    {
                    };
                    video.LocalFilePath = (ConfigurationHandler.DealerImages + "/" + dealer.DealerId + "/" + car.Vin + "/NormalSizeImages") + String.Format(@"\{0} {1} {2} {3}.wmv", car.ModelYear, car.Make, car.Model, car.Trim);
                    video.Categories.Add("Autos");
                    video.Tags.Add(car.ModelYear.ToString());
                    video.Tags.Add(car.Make);
                    video.Tags.Add(car.Model);
                    video.Tags.Add(dealer.Name);
                    video.Tags.Add("Vehicle");
                    video.Tags.Add("Auto");
                    video.Description = car.Description;
                    video.Title       = String.Format(@"{0} {1} {2} {3}", car.ModelYear, car.Make, car.Model, car.Trim);
                    video.Latitude    = Convert.ToDouble(dealer.Lattitude);
                    video.Longitude   = Convert.ToDouble(dealer.Longitude);
                    string videoId;
                    youtube.UploadVideoToYouTube(video, out videoId);
                    return(videoId.Split(':').Last());
                }
                catch (Exception)
                {
                }
            }

            return(string.Empty);
        }
Exemple #3
0
        public IHttpActionResult Insert(DealerViewModel pDealer)
        {
            //TODO: Agregar usuario que hizo la acción
            ResponseApiViewModel rta = new ResponseApiViewModel();

            try
            {
                Dealer dealerToInsert    = DealerViewModel.PrepareDealerToInsertDB(pDealer);
                bool   dealerWasInserted = DealerViewModel.InsertIntoDB(dealerToInsert);

                if (dealerWasInserted)
                {
                    rta.response = true;
                    rta.message  = "El concesionario " + pDealer.document + " fue insertado correctamente en la base de datos.";
                    return(Ok(rta));
                }
                else
                {
                    rta.response = false;
                    rta.message  = "Ha ocurrido un error intentado insertar el dealente:  " + pDealer.document;
                    return(BadRequest(rta.message));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Exemple #4
0
        public async Task <ActionResult> Registration(DealerViewModel dealerViewModel)
        {
            List <DealerViewModel> dealers  = new List <DealerViewModel>();
            HttpResponseMessage    Response = await GlobalVariables.client.GetAsync("api/Dealer/CheckDealerEmail?email=" + dealerViewModel.Email);

            if (Response.IsSuccessStatusCode)
            {
                dealerViewModel.Password = hash(dealerViewModel.Password);
                dealerViewModel.Password.Replace('+', ' ');
                dealerViewModel.CreatedDate = DateTime.Now;
                dealerViewModel.RoleId      = 2;
                var stringContent = new StringContent(JsonConvert.SerializeObject(dealerViewModel), Encoding.UTF8, "application/json");
                var addressUri    = new Uri("api/Dealer/InsertDealer", UriKind.Relative);
                var Res           = GlobalVariables.client.PostAsync(addressUri, stringContent).Result;
                if (Res.IsSuccessStatusCode)
                {
                    string message = "<html><body>Your Account Successfully Created!!!<br><a href=\"LINK\">Click Here</a></body></html>";
                    var    link    = Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, "/Dealer/Dealer/Verify?email=" + dealerViewModel.Email + "");
                    message = message.Replace("LINK", link);
                    bool flag = await sendEmail.SendMail(dealerViewModel.Email, "Verify", message);

                    TempData["Verifylink"] = "Successfully send link";
                    return(RedirectToAction("LogIn", "User"));
                }
            }
            else
            {
                ModelState.AddModelError("Exits", "Email is already exits!");
            }

            return(View());
        }
        //Get:Create Dealer
        public ActionResult Create()
        {
            DealerViewModel model = new DealerViewModel();


            return(View(model));
        }
        public ActionResult Create(DealerViewModel dealerModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Dealer dealerObj = dbContext.Dealers.Find(dealerModel.Id);
                    if (dealerObj != null)
                    {
                        ModelState.AddModelError("", "The Dealer was created.");
                    }
                    else
                    {
                        Dealer dealerSave = dealerModel.ToDealer(dealerObj);

                        dbContext.Dealers.Add(dealerSave);
                        dbContext.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                }
            }
            catch (Exception)
            {
                ModelState.AddModelError("", "Unable to save changes. Try again, Please se Administrator.");
            }


            return(View(dealerModel));
        }
        public ActionResult Edit(DealerViewModel dealerModel)
        {
            var    dealerToUpdate = dbContext.Dealers.Find(dealerModel.Id);
            Dealer dealerNew      = dealerModel.ToDealer(dealerToUpdate);

            if (dealerToUpdate == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }


            if (ModelState.IsValid)
            {
                try
                {
                    dbContext.Dealers.Attach(dealerNew);
                    dbContext.Entry(dealerNew).State = EntityState.Modified;
                    dbContext.SaveChanges();

                    return(RedirectToAction("Index"));
                }
                catch (RetryLimitExceededException)
                {
                    ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
                }
            }
            DealerViewModel model = new DealerViewModel(dealerNew);

            return(View(model));
        }
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            HttpResponseMessage webResponse = webClient.GetAsync(webClient.BaseAddress + "/Dealers/getDealerByExID?exID=" + id).Result;
            DealerViewModel     dealer      = null;

            if (webResponse.IsSuccessStatusCode)
            {
                //Storing the response details recieved from web api
                var response = webResponse.Content.ReadAsStringAsync().Result;
                dealer      = JsonConvert.DeserializeObject <DealerViewModel>(response);
                webResponse = webClient.GetAsync(webClient.BaseAddress + "/Users/getAllUserDealer").Result;
                if (webResponse.IsSuccessStatusCode)
                {
                    var Response = webResponse.Content.ReadAsStringAsync().Result;
                    var dealers  = JsonConvert.DeserializeObject <List <UserDealerDropDown> >(Response);
                    TempData["UserID"] = new SelectList(dealers, "ID", "ID");
                }


                return(View(dealer));
            }

            return(HttpNotFound());
        }
Exemple #9
0
        // GET : /Distributor/Edit
        public ActionResult Edit(string dealerId)
        {
            DealerViewModel dealerVM = new DealerViewModel();

            if (Session["UserData"] is Admin)
            {
                var currentUser            = Session["UserData"] as Admin;
                var distributors           = GetDistributors(currentUser.UserId.ToString());
                var distributorsSelectList =
                    new SelectList(
                        distributors.Select(
                            dist => new SelectListItem()
                {
                    Text = dist.Username, Value = dist.UserId.ToString()
                }), "Value",
                        "Text");

                ViewData["DistributorList"] = distributorsSelectList;

                if (string.IsNullOrWhiteSpace(dealerId))
                {
                    dealerVM.UserId = Guid.Empty;
                }
                else
                {
                    var    dealerGuid = Guid.Parse(dealerId);
                    Dealer dealer     = _dealerService.GetUser(dealerGuid);
                    dealerVM = Mapper.Map <Dealer, DealerViewModel>(dealer);
                }
            }
            return(PartialView("_Edit", dealerVM));
        }
Exemple #10
0
        public List <DealerViewModel> getAllDealers()
        {
            List <DealerViewModel> list = new List <DealerViewModel>();

            try
            {
                var entities = _dbContext.Dealers.OrderBy(c => c.CreatedDate).ToList();

                if (entities != null)
                {
                    foreach (var item in entities)
                    {
                        //// TODO: automapper mapping

                        var             config = new MapperConfiguration(cfg => cfg.CreateMap <Models.Dealer, DealerViewModel>());
                        var             mapper = new Mapper(config);
                        DealerViewModel dealer = mapper.Map <DealerViewModel>(item);

                        list.Add(dealer);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(list);
        }
Exemple #11
0
        public void DealerClick(object sender, RoutedEventArgs e)
        {
            Dealer          view      = new Dealer();
            DealerViewModel viewModel = new DealerViewModel();

            view.DataContext = viewModel;
            view.ShowDialog();
        }
Exemple #12
0
 public ActionResult EditDealer(DealerViewModel viewModel)
 {
     if (ModelState.IsValid)
     {
         var result = _DealerManager.UpdateDealer(viewModel);
         return(RedirectToAction("ListDealer"));
     }
     return(View(viewModel));
 }
Exemple #13
0
        public string UpdateDealer(DealerViewModel viewModel)
        {
            var Dealer = mapper.Map <DealerViewModel, Dealer>(viewModel);

            Dealer.UpdatedDate = DateTime.Now;
            var result = _DealerRepository.UpdateDealer(Dealer);

            return(result);
        }
Exemple #14
0
        public IHttpActionResult InsertDealer(DealerViewModel dealerViewModel)
        {
            bool status = _dealerManager.InsertDealer(dealerViewModel);

            if (status == false)
            {
                return(Json("Dealer Details not Inserted"));
            }
            return(Ok());
        }
Exemple #15
0
        public bool InsertDealer(DealerViewModel dealerViewModel)
        {
            var config = new MapperConfiguration(cfg => {
                cfg.CreateMap <DealerViewModel, CMS_DealerInfo>();
            });
            IMapper mapper = config.CreateMapper();
            var     dealer = mapper.Map <DealerViewModel, CMS_DealerInfo>(dealerViewModel);

            return(_dealerRepository.InsertDealer(dealer));
        }
        public PartialViewResult DealCardDealer()
        {
            var    theGame = GetGame();
            Dealer dealer  = theGame.Dealer;

            theGame.DealCard(dealer);

            DealerViewModel vm = new DealerViewModel(dealer);

            return(PartialView("_Dealer", vm));
        }
Exemple #17
0
        public ViewResult UpdateDealer(int Id)
        {
            var dealer    = db.Dealer.Single(d => d.TraderId == usr_id && d.Id == Id);
            var newDealer = new DealerViewModel
            {
                Name     = dealer.Name,
                TraderId = dealer.TraderId,
                Id       = dealer.Id
            };

            return(View(newDealer));
        }
 public ActionResult Create(DealerViewModel model)
 {
     if (ModelState.IsValid)
     {
         HttpResponseMessage webResponse = webClient.PostAsJsonAsync(webClient.BaseAddress + "/Dealers/registerDealer", model).Result;
         if (webResponse.IsSuccessStatusCode)
         {
             return(RedirectToAction("Index"));
         }
     }
     return(View(model));
 }
Exemple #19
0
        public HttpResponseMessage getAllDealerByUser(string userExID)
        {
            DealerViewModel result = _dealerManager.getAllDealerByUser(userExID);

            if (result != null)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, result));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized));
            }
        }
Exemple #20
0
        public HttpResponseMessage getDealerByID(long ID)
        {
            DealerViewModel result = _dealerManager.getDealerByID(ID);

            if (result != null)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, result));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized));
            }
        }
Exemple #21
0
        public HttpResponseMessage updateDealerDetails([FromBody] DealerViewModel model)
        {
            bool result = _dealerManager.updateDealerDetails(model);

            if (result)
            {
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.NotModified));
            }
        }
Exemple #22
0
        public IHttpActionResult Update(DealerViewModel pDealer)
        {
            //TODO: Agregar usuario que hizo la acción
            try
            {
                ResponseApiViewModel rta = new ResponseApiViewModel();
                using (DB_FleetServiceEntities db = new DB_FleetServiceEntities())
                {
                    var oDealerDB = db.Dealer.Where(dlr => dlr.deal_id == pDealer.id || dlr.deal_document == pDealer.document)
                                    .FirstOrDefault();
                    if (oDealerDB != null)
                    {
                        if (pDealer.document.Trim() == "")
                        {
                            throw new Exception("El documento del concesionario no es válido");
                        }

                        long numberOfDocument;
                        bool documentIsValid = long.TryParse(pDealer.document, out numberOfDocument);

                        if (!documentIsValid)
                        {
                            throw new Exception("El documento del concesionario no es válido, intente ingresarlo sin dígito de verificación, sin puntos ni comas.");
                        }

                        if (pDealer.name.Trim() == "")
                        {
                            throw new Exception("El nombre del concesionario es obligatorio, no se puede insertar a la base de datos sin esta información");
                        }

                        oDealerDB.deal_document   = pDealer.document;
                        oDealerDB.deal_name       = pDealer.name.ToUpper();
                        oDealerDB.deal_updateDate = DateTime.Now;
                        db.SaveChanges();
                        rta.response = true;
                        rta.message  = "Se ha actualizado el concesionario: " + pDealer.document + " - " + pDealer.name;
                        return(Ok(rta));
                    }
                    else
                    {
                        rta.response = false;
                        rta.message  = "No se encontró el concesionario: " + pDealer.document + " - " + pDealer.name + " en la base de datos, por favor rectifique los datos";
                        return(BadRequest(rta.message));
                    }
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Exemple #23
0
 public ActionResult UpdateDealer(DealerViewModel vm)
 {
     if (ModelState.IsValid)
     {
         var dealer = db.Dealer.Find(vm.Id);
         dealer.Name     = vm.Name;
         dealer.TraderId = usr_id;
         db.SaveChanges();
         return(RedirectToAction("GetDealers"));
     }
     else
     {
         return(RedirectToAction("GetDealers"));
     }
 }
Exemple #24
0
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HttpResponseMessage webResponse = webClient.GetAsync(webClient.BaseAddress + "/Bookings/getBookingByExID?exID=" + id).Result;
            BookingViewModel    booking     = null;

            if (webResponse.IsSuccessStatusCode)
            {
                //Storing the response details recieved from web api
                var response = webResponse.Content.ReadAsStringAsync().Result;
                booking     = JsonConvert.DeserializeObject <BookingViewModel>(response);
                webResponse = webClient.GetAsync(webClient.BaseAddress + "/Dealers/getDealerByID?ID=" + booking.DealerID).Result;
                DealerViewModel dealer = null;
                if (webResponse.IsSuccessStatusCode)
                {
                    response = webResponse.Content.ReadAsStringAsync().Result;
                    dealer   = JsonConvert.DeserializeObject <DealerViewModel>(response);
                }
                else
                {
                }

                webResponse = webClient.GetAsync(webClient.BaseAddress + "/Mechanics/getAllMechanicsByDealer?dealerExID=" + dealer.ExternalID.ToString()).Result;

                if (webResponse.IsSuccessStatusCode)
                {
                    response = webResponse.Content.ReadAsStringAsync().Result;
                    var mechanics = JsonConvert.DeserializeObject <List <MechanicDropDown> >(response);
                    TempData["mechanics"] = new SelectList(mechanics, "ID", "Name");
                }
                webResponse = webClient.GetAsync(webClient.BaseAddress + "/Services/getAllServicesByDealerDrop?dealerExID=" + dealer.ExternalID.ToString()).Result;

                if (webResponse.IsSuccessStatusCode)
                {
                    response = webResponse.Content.ReadAsStringAsync().Result;
                    var services = JsonConvert.DeserializeObject <List <ServiceDropDown> >(response);
                    TempData["services"] = new SelectList(services, "ID", "Name");
                }


                return(View(booking));
            }

            return(HttpNotFound());
        }
        public ActionResult Details(int?Id)
        {
            if (Id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Dealer dealers = dbContext.Dealers.Find(Id);

            if (dealers == null)
            {
                return(HttpNotFound());
            }
            DealerViewModel model = new DealerViewModel(dealers);

            return(View(model));
        }
Exemple #26
0
 public ActionResult AddDealer(DealerViewModel dealer)
 {
     if (ModelState.IsValid)
     {
         db.Dealer.Add(new Dealer
         {
             Name     = dealer.Name,
             TraderId = usr_id
         });
         db.SaveChanges();
         return(RedirectToAction("GetDealers"));
     }
     else
     {
         return(RedirectToAction("GetDealers"));
     }
 }
Exemple #27
0
        public ActionResult Add(DealerViewModel model)
        {
            HttpPostedFileBase file = Request.Files["fileUpload"];

            if (ModelState.IsValid)
            {
                try
                {
                    var dealer = Mapper.Map <DealerViewModel, Dealer>(model);

                    if (Session["UserData"] is Distributor)
                    {
                        dealer.Parent = ((Distributor)Session["UserData"]).UserId;
                    }
                    else
                    {
                        dealer.Parent    = Guid.Parse(Request.Form["distributorId"]);
                        dealer.ImageName = file.FileName;
                        dealer.Logo      = ConvertToBytes(file);
                    }

                    _dealerService.CreateDealer(dealer);
                    _dealerService.SaveDealer();

                    return(RedirectToAction("Index", "Dealer"));
                }

                catch (InvalidOperationException ex)
                {
                    ModelState.AddModelError("Error", ex.Message);
                }

                catch (Exception ex)
                {
                    ModelState.AddModelError("Error", ex.Message);
                }
            }

            if (Request.IsAjaxRequest())
            {
                return(PartialView("_Add", model));
            }

            return(View(model));
        }
        public ActionResult Create(DealerViewModel dealer)
        {
            if (!ModelState.IsValid)
            {
                return(View(dealer));
            }

            try
            {
                FakeDatabase.Add(dealer);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View("Edit", dealer));
            }
        }
        // GET: Edit Dealer
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Dealer dealer = dbContext.Dealers.Find(id);

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

            DealerViewModel model = new DealerViewModel(dealer);

            return(View(model));
        }
        public ActionResult Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HttpResponseMessage webResponse = webClient.GetAsync(webClient.BaseAddress + "/Dealers/getDealerByExID?exID=" + id).Result;
            DealerViewModel     dealer      = null;

            if (webResponse.IsSuccessStatusCode)
            {
                //Storing the response details recieved from web api
                var response = webResponse.Content.ReadAsStringAsync().Result;
                dealer = JsonConvert.DeserializeObject <DealerViewModel>(response);
                return(View(dealer));
            }
            else
            {
                return(HttpNotFound());
            }
        }
 /// <summary>
 /// Initializes a new instance of the DealerHandViewModel class.
 /// </summary>
 /// <param name="ParentTVM">Placeholder for the parent MasterViewModel.</param>
 /// <param name="ParentDVM">Placeholder for the parent DealerViewModel.</param>
 public DealerHandViewModel(TableViewModel ParentTVM, DealerViewModel ParentDVM)
 {
     m_MasterParent = ParentTVM;
     m_ParentDealerViewModel = ParentDVM;
     m_DealerHandModel = new DealerHandModel();
 }
 private void DealerSeatUC_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
 {
     m_DealerViewModel = (DealerViewModel)DataContext;
 }