public ActionResult Edit(int modelId)
        {
            ModelVM model = _repo.ConvertModelToVM(_repo.GetModelById(modelId));

            model.SetMakeItems(_repo.GetMakeList());
            return(View(model));
        }
 public ActionResult Edit(ModelVM model)
 {
     if (!String.IsNullOrEmpty(model.Description) && model.MakeId > 0)
     {
         model.EditUserId = CurrentUser.User.Id;
         model.EditDate   = DateTime.Now;
         model            = _repo.UpdateModel(model);
         if (model.Result.Success)
         {
             return(RedirectToAction("List"));
         }
     }
     else if (String.IsNullOrEmpty(model.Description))
     {
         model.Result              = _repo.ReturnSuccess();
         model.Result.Success      = false;
         model.Result.ErrorMessage = "Description is required";
     }
     else if (model.MakeId <= 0)
     {
         model.Result              = _repo.ReturnSuccess();
         model.Result.Success      = false;
         model.Result.ErrorMessage = "Please choose make";
     }
     model.Result.Success = false;
     model.SetMakeItems(_repo.GetMakeList());
     return(View(model));
 }
Example #3
0
        public ActionResult AddModel(ModelVM modelVM)
        {
            var repo = VehicleComponentsRepoFactory.CreateVehicleComponentsRepo();

            if (ModelState.IsValid)
            {
                modelVM.ModelToADO = new Model();

                modelVM.ModelToADO.ModelName = modelVM.NameOfNewModel;
                modelVM.ModelToADO.MakeName  = modelVM.MakeName;

                //fake work-around until security is in place
                modelVM.ModelToADO.UserName = "******";

                repo.InsertModel(modelVM.ModelToADO);

                return(RedirectToAction("AddModel", "Admin"));
            }
            else
            {
                modelVM.Makes  = GetMakeSelectList();
                modelVM.Models = repo.GetAllModels();

                return(View(modelVM));
            }
        }
        public ActionResult Add()
        {
            ModelVM model = _repo.ConvertModelToVM(new Model());

            model.SetMakeItems(_repo.GetMakeList());
            return(View(model));
        }
Example #5
0
        /// <summary>
        /// Sets the View Model for the Texture and Model tab when an item is selected from the treeview
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TreeView_SelectionChanged(object sender, PropertyChangedEventArgs e)
        {
            var itemVM = sender as ItemViewModel;

            if (itemVM.IsSelected)
            {
                //dispose of the data from teh previously selected item
                if (ModelVM != null)
                {
                    ModelVM.Dispose();
                }

                TextureVM = new TextureViewModel(itemVM.Item, ((CategoryViewModel)itemVM.Parent).CategoryName);

                if (itemVM.ItemName.Equals(Strings.Face_Paint) || itemVM.ItemName.Equals(Strings.Equipment_Decals))
                {
                    if (ModelVM != null)
                    {
                        ModelVM.ModelTabEnabled = false;
                    }
                }
                else
                {
                    ModelVM = new ModelViewModel(itemVM.Item, ((CategoryViewModel)itemVM.Parent).CategoryName);
                    ModelVM.ModelTabEnabled = true;
                }
            }
        }
Example #6
0
        public async Task <ApiResultVM <string> > Update(ModelVM modelVM, int id)
        {
            var checkValue = await GetById(id);

            if (checkValue == null)
            {
                _dbContextDTO.Dispose();
                return(new ApiErrorResultVM <string>("Model doesn't exist"));
            }
            var checkModel = await dbset.Where(x => x.Id != id).Where(x => x.Name.Equals(modelVM.Name)).AsNoTracking().FirstOrDefaultAsync();

            if (checkModel != null)
            {
                _dbContextDTO.Dispose();
                return(new ApiErrorResultVM <string>("Model's name already exist"));
            }
            var modelDTO = _mapper.Map <ModelDTO>(modelVM);

            modelDTO.Id       = id;
            modelDTO.UpdateAt = DateTime.Now;
            dbset.Update(modelDTO);
            await _dbContextDTO.SaveChangesAsync();

            return(new ApiSuccessResultVM <string>("Update Success"));
        }
Example #7
0
        public ActionResult Models()
        {
            ModelVM modelVM = new ModelVM();

            modelVM.Models = modelRepo.GetAll();
            modelVM.Makes  = new SelectList(makeRepo.GetAll(), "MakeId", "MakeName");
            return(View(modelVM));
        }
        private void EditMenuItem_Click(object sender, RoutedEventArgs e)
        {
            btnUpdate.IsEnabled = true;
            ModelVM model = (DBGrid.SelectedItem as ModelVM);

            txtModel.Text = model.Name;
            cbMake.Text   = model.Make.Name;
        }
Example #9
0
        public static ClientCredentials GetClient(this ModelVM model)
        {
            var client = new ClientCredentials
            {
                Email = model.Email
            };

            return(client);
        }
        ModelVM GetAllMakes()
        {
            var vmodel = new ModelVM
            {
                Marques = FillSelectList()
            };

            return(vmodel);
        }
 public ModelsController(CarsRentalContext context, IStringLocalizer <ModelsController> localizer)
 {
     _context   = context;
     _localizer = localizer;
     VM         = new ModelVM()
     {
         Marques = _context.Marques.ToList(),
         Model   = new Models.Model()
     };
 }
Example #12
0
        public ActionResult AddModel()
        {
            ModelVM modelVM = new ModelVM();
            var     repo    = VehicleComponentsRepoFactory.CreateVehicleComponentsRepo();

            modelVM.Makes  = GetMakeSelectList();
            modelVM.Models = repo.GetAllModels();

            return(View(modelVM));
        }
Example #13
0
        public void OpenID(ItemData item, string race, string category, string part, string variant)
        {
            if (ModelVM != null)
            {
                ModelVM.Dispose();
            }

            TextureVM.UpdateTextureFromID(item, race, category, part, variant);
            ModelVM.UpdateModel(item, category);
            ModelVM.ModelTabEnabled = true;
        }
        public async Task <ApiResultVM <string> > Insert(ModelVM modelVM, string token)
        {
            var client = _httpClientFactory.CreateClient();

            client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
            client.BaseAddress = new Uri(_configuration["UrlApi"]);
            var response = await client.PostAsJsonAsync("/api/models", modelVM);

            var body = await response.Content.ReadAsStringAsync();

            return(JsonConvert.DeserializeObject <ApiResultVM <string> >(body));
        }
 public ActionResult Delete(ModelVM model)
 {
     model.Result = _repo.DeleteModel(model);
     if (model.Result.Success)
     {
         return(RedirectToAction("List"));
     }
     else
     {
         return(View(model));
     }
 }
Example #16
0
        public Response DeleteModel(ModelVM model)
        {
            model.Result = ReturnSuccess();
            if (GetCarList().Any(m => m.ModelId == model.ModelId))
            {
                model.Result.Success      = false;
                model.Result.ErrorMessage = model.Description + " is in used";
                return(model.Result);
            }

            _modelList.RemoveAll(m => m.ModelId == model.ModelId);
            return(ReturnSuccess());
        }
Example #17
0
        public ActionResult List()
        {
            #region Cart list

            HttpCookie    cookieCart = Request.Cookies["Cart"];
            List <string> CartList   = new List <string>();
            if (cookieCart != null)
            {
                CartList = cookieCart.Value.Split(',').ToList();
                CartList.RemoveAt(CartList.Count - 1);

                ViewBag.CartList      = CartList;
                ViewBag.CartListCount = CartList.Count;
            }
            else
            {
                ViewBag.CartListCount = 0;
            }

            List <Product> products = new List <Product>();

            foreach (var item in CartList)
            {
                foreach (var prd in db.Products.Include("ProductImages").Include("Admin").Include("ProductToCategory").Include("ProductToCategory.ProductCategory").ToList())
                {
                    if (Convert.ToInt32(item.Split('-')[0]) == prd.Id)
                    {
                        prd.Count = Convert.ToDecimal(item.Split('-')[1]);
                        products.Add(prd);
                    }
                }
            }
            ViewBag.Products = products;
            #endregion

            ViewBag.ModelPage = true;

            ViewBag.Blogs      = db.Blog.Where(c => c.isActive).OrderByDescending(c => c.PostDate).Take(3).ToList();
            ViewBag.Address    = db.Layout.FirstOrDefault().Address;
            ViewBag.Phone      = db.Layout.FirstOrDefault().Phone;
            ViewBag.Email      = db.Layout.FirstOrDefault().Email;
            ViewBag.FooterLogo = db.Layout.FirstOrDefault().LogoFooter;
            ViewBag.HeaderLogo = db.Layout.FirstOrDefault().Logo;
            ModelVM v = new ModelVM();

            v.Models = db.Model.Where(c => c.isActive == true).Include("ModelImages").Include("Brand").ToList();
            v.Brands = db.Brand.Where(c => c.isActive == true).Include("Models").Include("Models.ModelImages").ToList();


            return(View(v));
        }
        public Response DeleteModel(ModelVM model)
        {
            model.Result = ReturnSuccess();
            if (GetCarList().Any(m => m.ModelId == model.ModelId))
            {
                model.Result.Success      = false;
                model.Result.ErrorMessage = model.Description + " is in used";
                return(model.Result);
            }

            _ctx.Entry(model).State = System.Data.Entity.EntityState.Deleted;
            _ctx.SaveChanges();
            return(ReturnSuccess());
        }
Example #19
0
        public ModelVM AddModel(ModelVM model)
        {
            model.Result = ReturnSuccess();
            if (GetMakeList().Any(m => m.Description == model.Description))
            {
                model.Result.Success      = false;
                model.Result.ErrorMessage = model.Description + " is alreay existed";
                return(model);
            }

            model.ModelId = _modelList.Count + 1;
            _modelList.Add(ConvertVMToModel(model));
            return(model);
        }
 public ModelVM UpdateModel(ModelVM model)
 {
     model.Result = ReturnSuccess();
     if (GetModelList().Any(m => m.Description == model.Description && m.ModelId != model.ModelId))
     {
         model.Result.Success      = false;
         model.Result.ErrorMessage = model.Description + " is alreay existed";
         return(model);
     }
     _ctx.Set <Model>().AddOrUpdate(ConvertVMToModel(model));
     //_ctx.Entry(ConvertVMToModel(model)).State = System.Data.Entity.EntityState.Modified;
     _ctx.SaveChanges();
     return(model);
 }
Example #21
0
        public ModelVM UpdateModel(ModelVM model)
        {
            model.Result = ReturnSuccess();
            if (GetModelList().Any(m => m.Description == model.Description && m.ModelId != model.ModelId))
            {
                model.Result.Success      = false;
                model.Result.ErrorMessage = model.Description + " is alreay existed";
                return(model);
            }

            _modelList.RemoveAll(m => m.ModelId == model.ModelId);
            _modelList.Add(ConvertVMToModel(model));
            return(model);
        }
Example #22
0
        //public IActionResult Index(id)
        public IActionResult Index(int id)
        {
            ///            var motocykl = _motocyklRepository.PobierzMotocykl(id);

            ///         if (motocykl == null)
            //          return NotFound();
            var motocykle = _motocyklRepository.GetModels(id);

            string modelname = "none";

            switch (id)
            {
            case 1:
                modelname = "BMW";
                break;

            case 2:
                modelname = "Ducati";
                break;

            case 3:
                modelname = "Kawasaki";
                break;

            case 4:
                modelname = "KTM";
                break;

            case 5:
                modelname = "Timbersled";
                break;

            case 6:
                modelname = "Triumph";
                break;

            case 7:
                modelname = "Yeti snowMX";
                break;
            }


            var modelVM = new ModelVM
            {
                MyModel   = modelname,
                Motocykle = motocykle.ToList()
            };

            return(View(modelVM));
        }
Example #23
0
        public dynamic PutModel(ModelVM m)
        {
            var model = db.Models.Find(m.ID);

            model.NameAr  = m.NameAr;
            model.NameEn  = m.NameEn;
            model.BrandId = m.BrandId;
            var result = db.SaveChanges() > 0 ? true : false;

            return(new
            {
                result = result
            });
        }
Example #24
0
        public ActionResult Models(ModelVM carModel)
        {
            Model model = new Model();

            {
                model.ModelName = carModel.ModelName;
                model.MakeID    = carModel.MakeID;
                model.DateAdded = DateTime.Now;
                model.UserId    = "1";
            }

            Factory.ModelRepo().Create(model);

            return(RedirectToAction("Models"));
        }
        public ModelVM AddModel(ModelVM model)
        {
            model.Result = ReturnSuccess();
            if (GetMakeList().Any(m => m.Description == model.Description))
            {
                model.Result.Success      = false;
                model.Result.ErrorMessage = model.Description + " is alreay existed";
                return(model);
            }

            _ctx.Models.Add(ConvertVMToModel(model));
            _ctx.SaveChanges();
            model.ModelId = _ctx.Models.Max(m => m.ModelId);
            return(model);
        }
Example #26
0
        public dynamic PostModel(ModelVM m)
        {
            var model = db.Models.Add(new Model
            {
                NameAr  = m.NameAr,
                NameEn  = m.NameEn,
                BrandId = m.BrandId,
            });
            var result = db.SaveChanges() > 0 ? true : false;

            return(new
            {
                result = result,
                modelId = model.Id
            });
        }
Example #27
0
        public Model ConvertVMToModel(ModelVM modelVM)
        {
            Model result = new Model()
            {
                AddDate     = modelVM.AddDate,
                AddUserId   = modelVM.AddUserId,
                Description = modelVM.Description,
                EditDate    = modelVM.EditDate,
                EditUserId  = modelVM.EditUserId,
                Make        = GetMakeById(modelVM.MakeId),
                MakeId      = modelVM.MakeId,
                ModelId     = modelVM.ModelId
            };

            return(result);
        }
        public Model ConvertVMToModel(ModelVM modelVM)
        {
            Model result = new Model()
            {
                AddDate     = modelVM.AddDate,
                AddUserId   = modelVM.AddUserId,
                Description = modelVM.Description,
                EditDate    = modelVM.EditDate.Year < 1900 ? DateTime.Parse("01/01/1900") : modelVM.EditDate,
                EditUserId  = modelVM.EditUserId,
                Make        = GetMakeById(modelVM.MakeId),
                MakeId      = modelVM.MakeId,
                ModelId     = modelVM.ModelId
            };

            return(result);
        }
Example #29
0
        public async Task <ActionResult> CreateAsync([Bind(Include = "VehicleModelId,VehicleMakeId,Name,Abrv")] ModelVM modelVM)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var dest = Mapper.Map <VehicleModel>(modelVM);
                    await service.CreateAsync(dest);

                    return(RedirectToAction(""));
                }
            }
            catch (Exception ex)
            {
                // throw ex;
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, ex.Message));
            }
            return(View(modelVM));
        }
        public ModelVM ConvertModelToVM(Model model)
        {
            ModelVM result = new ModelVM()
            {
                AddDate     = model.AddDate,
                AddUser     = GetUserById(model.AddUserId),
                AddUserId   = model.AddUserId,
                Description = model.Description,
                EditDate    = model.EditDate,
                EditUser    = GetUserById(model.EditUserId),
                EditUserId  = model.EditUserId,
                Make        = GetMakeById(model.MakeId),
                MakeId      = model.MakeId,
                ModelId     = model.ModelId,
                Result      = ReturnSuccess()
            };

            return(result);
        }