private void EditMenuItem_Click(object sender, RoutedEventArgs e)
        {
            btnUpdate.IsEnabled = true;
            MakeVM make = (DBGrid.SelectedItem as MakeVM);

            txtMake.Text = make.Name;
        }
        public async Task <ApiResultVM <string> > Update(MakeVM makeVM, int id)
        {
            var checkValue = await GetById(id);

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

            if (checkMake != null)
            {
                _dbContextDTO.Dispose();
                return(new ApiErrorResultVM <string>("Make's name already exist"));
            }
            var makeDTO = _mapper.Map <MakeDTO>(makeVM);

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

            return(new ApiSuccessResultVM <string>("Update Success"));
        }
Beispiel #3
0
        public ActionResult Makes()
        {
            var model = new MakeVM();

            model.Makes = Factory.MakeRepo().Get();

            return(View(model));
        }
Beispiel #4
0
        public ActionResult Makes()
        {
            MakeVM makeVM = new MakeVM();

            makeVM.Makes = makeRepo.GetAll();

            return(View(makeVM));
        }
        public ActionResult AddMake()
        {
            MakeVM makeVM = new MakeVM();
            var    repo   = VehicleComponentsRepoFactory.CreateVehicleComponentsRepo();

            makeVM.Makes = repo.GetAllMakes();

            return(View(makeVM));
        }
Beispiel #6
0
        public ActionResult Makes(MakeVM makeVM)
        {
            var userManager = HttpContext.GetOwinContext().GetUserManager <UserManager <AppUser> >();
            var authManager = HttpContext.GetOwinContext().Authentication;

            makeVM.Make.UserId = authManager.User.Identity.GetUserId();

            makeRepo.Create(makeVM.Make);
            return(RedirectToAction("Makes"));
        }
 public ActionResult Delete(MakeVM model)
 {
     model.Result = _repo.DeleteMake(model);
     if (model.Result.Success)
     {
         return(RedirectToAction("List"));
     }
     else
     {
         return(View(model));
     }
 }
        public async Task <ApiResultVM <string> > Insert(MakeVM makeVM, string token)
        {
            var client = _httpClientFactory.CreateClient();

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

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

            return(JsonConvert.DeserializeObject <ApiResultVM <string> >(body));
        }
Beispiel #9
0
        public Response DeleteMake(MakeVM make)
        {
            make.Result = ReturnSuccess();
            if (GetModelList().Any(m => m.MakeId == make.MakeId))
            {
                make.Result.Success      = false;
                make.Result.ErrorMessage = make.Description + " is in used";
                return(make.Result);
            }

            _makeList.RemoveAll(m => m.MakeId == make.MakeId);
            return(ReturnSuccess());
        }
Beispiel #10
0
        public ActionResult Makes(MakeVM make)
        {
            Make model = new Make();

            {
                model.MakeName  = make.MakeName;
                model.DateAdded = DateTime.Now;
                model.UserId    = "1";
            }

            Factory.MakeRepo().Create(model);

            return(RedirectToAction("Makes"));
        }
Beispiel #11
0
        public Make ConvertVMToMake(MakeVM input)
        {
            Make result = new Make()
            {
                AddDate     = input.AddDate,
                AddUserId   = input.AddUserId,
                Description = input.Description,
                EditDate    = input.EditDate,
                EditUserId  = input.EditUserId,
                MakeId      = input.MakeId,
            };

            return(result);
        }
        public Make ConvertVMToMake(MakeVM input)
        {
            Make result = new Make()
            {
                AddDate     = input.AddDate,
                AddUserId   = input.AddUserId,
                Description = input.Description,
                EditDate    = input.EditDate.Year < 1900 ? DateTime.Parse("01/01/1900").Date : input.EditDate,
                EditUserId  = input.EditUserId,
                MakeId      = input.MakeId,
            };

            return(result);
        }
 public MakeVM UpdateMake(MakeVM make)
 {
     make.Result = ReturnSuccess();
     if (GetMakeList().Any(m => m.Description == make.Description && m.MakeId != make.MakeId))
     {
         make.Result.Success      = false;
         make.Result.ErrorMessage = make.Description + " alreay existed";
         return(make);
     }
     _ctx.Set <Make>().AddOrUpdate(ConvertVMToMake(make));
     //_ctx.Entry(tmp).State = System.Data.Entity.EntityState.Modified;
     _ctx.SaveChanges();
     return(make);
 }
        public Response DeleteMake(MakeVM make)
        {
            make.Result = ReturnSuccess();
            if (GetModelList().Any(m => m.MakeId == make.MakeId))
            {
                make.Result.Success      = false;
                make.Result.ErrorMessage = make.Description + " is in used";
                return(make.Result);
            }

            _ctx.Entry(ConvertVMToMake(make)).State = System.Data.Entity.EntityState.Deleted;
            _ctx.SaveChanges();
            return(ReturnSuccess());
        }
Beispiel #15
0
        public MakeVM AddMake(MakeVM make)
        {
            make.Result = ReturnSuccess();
            if (GetMakeList().Any(m => m.Description == make.Description))
            {
                make.Result.Success      = false;
                make.Result.ErrorMessage = make.Description + " is alreay existed";
                return(make);
            }

            make.MakeId = _makeList.Count + 1;
            _makeList.Add(ConvertVMToMake(make));
            return(make);
        }
Beispiel #16
0
        public MakeVM UpdateMake(MakeVM make)
        {
            make.Result = ReturnSuccess();
            if (GetMakeList().Any(m => m.Description == make.Description && m.MakeId != make.MakeId))
            {
                make.Result.Success      = false;
                make.Result.ErrorMessage = make.Description + " is alreay existed";
                return(make);
            }

            _makeList.RemoveAll(m => m.MakeId == make.MakeId);
            _makeList.Add(ConvertVMToMake(make));
            make.Result = ReturnSuccess();
            return(make);
        }
        public MakeVM AddMake(MakeVM make)
        {
            make.Result = ReturnSuccess();
            if (GetMakeList().Any(m => m.Description == make.Description))
            {
                make.Result.Success      = false;
                make.Result.ErrorMessage = make.Description + " alreay existed";
                return(make);
            }

            _ctx.Makes.Add(ConvertVMToMake(make));
            _ctx.SaveChanges();
            make.MakeId = _ctx.Makes.Max(m => m.MakeId);
            return(make);
        }
        public MakeVM ConvertMakeToVM(Make input)
        {
            MakeVM result = new MakeVM()
            {
                AddDate     = input.AddDate,
                AddUser     = GetUserById(input.AddUserId),
                AddUserId   = input.AddUserId,
                Description = input.Description,
                EditDate    = input.EditDate,
                EditUser    = GetUserById(input.EditUserId),
                EditUserId  = input.EditUserId,
                MakeId      = input.MakeId,
                Result      = ReturnSuccess()
            };

            return(result);
        }
 private async void BtnAddModel_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         lblErrorModel.Foreground = Brushes.White;
         lblErrorMake.Foreground  = Brushes.White;
         lblErrorMake.Content     = "";
         lblErrorModel.Content    = "";
         ModelApiService service = new ModelApiService();
         MakeVM          make    = (cbMake.SelectedItem as MakeVM);
         ShowMessage(await service.CreateAsync(new ModelAddVM {
             Name = txtModel.Text, Make = make
         }));
     }
     catch (WebException wex)
     {
         ShowException(wex);
     }
 }
        public async Task <ApiResultVM <string> > Insert(MakeVM makeVM)
        {
            var checkMake = await dbset.Where(x => x.Name.Equals(makeVM.Name)).Where(x => x.isDelete == false).AsNoTracking().FirstOrDefaultAsync();

            if (checkMake != null)
            {
                _dbContextDTO.Dispose();
                return(new ApiErrorResultVM <string>("Make's name already exist"));
            }
            var makeDTO = _mapper.Map <MakeDTO>(makeVM);

            makeDTO.CreateAt = DateTime.Now;
            makeDTO.UpdateAt = DateTime.Now;
            await dbset.AddAsync(makeDTO);

            await _dbContextDTO.SaveChangesAsync();

            return(new ApiSuccessResultVM <string>("Insert Success"));
        }
Beispiel #21
0
        public async Task <ActionResult> CreateAsync([Bind(Include = "Id,Name,Abrv")] MakeVM makeVM)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var dest = Mapper.Map <VehicleMake>(makeVM);
                    await service.CreateAsync(dest);

                    return(RedirectToAction(""));
                }
            }
            catch (Exception ex)
            {
                // throw ex;
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, ex.Message));
            }
            return(View(makeVM));
        }
Beispiel #22
0
        public async Task <IActionResult> InsertAction(MakeVM makeVM)
        {
            if (ModelState.IsValid)
            {
                string token  = HttpContext.Session.GetString("token_access");
                var    result = await _makeServiceApiClient.Insert(makeVM, token);

                if (result.IsSuccessed == true)
                {
                    TempData["SuccessResult"] = result.Entity;
                    return(RedirectToAction("GetAll", "make"));
                }
                else
                {
                    ModelState.AddModelError("", result.Message);
                    return(View("Insert", makeVM));
                }
            }
            return(View("Insert", makeVM));
        }
 private async void DeleteMenuItem_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (DBGrid.SelectedItem != null)
         {
             MakeVM         make    = (DBGrid.SelectedItem as MakeVM);
             MakeApiService service = new MakeApiService();
             int            id      = make.Id;
             ShowMessage(await service.DeleteAsync(new MakelDeleteVM {
                 Id = id
             }));
             GetMakes();
         }
     }
     catch (WebException wex)
     {
         ShowException(wex);
     }
 }
 public ActionResult Edit(MakeVM model)
 {
     if (!string.IsNullOrEmpty(model.Description))
     {
         model.EditUserId = CurrentUser.User.Id;
         model.EditDate   = DateTime.Now;
         model            = _repo.UpdateMake(model);
         if (model.Result.Success)
         {
             return(RedirectToAction("List"));
         }
     }
     else
     {
         model.Result              = _repo.ReturnSuccess();
         model.Result.Success      = false;
         model.Result.ErrorMessage = "Description is required";
     }
     return(View(model));
 }
        public IActionResult Update([FromBody] MakeVM model)
        {
            if (!ModelState.IsValid)
            {
                var errors = CustomValidator.GetErrorsByModel(ModelState);
                return(BadRequest(errors));
            }
            var make = _context.Makes.SingleOrDefault(p => p.Id == model.Id);

            if (make != null)
            {
                make = _context.Makes.SingleOrDefault(p => p.Name == model.Name);
                if (make == null)
                {
                    make.Name = model.Name;
                    _context.SaveChanges();
                    return(Ok("Дані оновлено"));
                }
            }
            return(BadRequest(new { name = "Помилка оновлення" }));
        }
 private async void BtnUpdate_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (DBGrid.SelectedItem != null)
         {
             MakeApiService service = new MakeApiService();
             MakeVM         make    = (DBGrid.SelectedItem as MakeVM);
             int            id      = make.Id;
             ShowMessage(await service.UpdateAsync(new MakeVM {
                 Id = id, Name = txtMake.Text
             }));
             btnUpdate.IsEnabled = false;
             GetMakes();
         }
     }
     catch (WebException wex)
     {
         ShowException(wex);
     }
 }
Beispiel #27
0
        public ActionResult AddMake(MakeVM makeVM)
        {
            var repo = VehicleComponentsRepoFactory.CreateVehicleComponentsRepo();

            if (ModelState.IsValid)
            {
                makeVM.MakeToADO = new Make();

                makeVM.MakeToADO.MakeName = makeVM.NameOfNewMake;

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

                repo.InsertMake(makeVM.MakeToADO);
                return(RedirectToAction("AddMake", "Admin"));
            }
            else
            {
                makeVM.Makes = repo.GetAllMakes();
                return(View(makeVM));
            }
        }
        public string Update(MakeVM make)
        {
            var http = (HttpWebRequest)WebRequest.Create(new Uri(_url));

            http.Accept      = "application/json";
            http.ContentType = "application/json";
            http.Method      = "PUT";

            string       parsedContent = JsonConvert.SerializeObject(make);
            UTF8Encoding encoding      = new UTF8Encoding();

            Byte[] bytes     = encoding.GetBytes(parsedContent);
            Stream newStream = http.GetRequestStream();

            newStream.Write(bytes, 0, bytes.Length);
            newStream.Close();

            var response = http.GetResponse();
            var stream   = response.GetResponseStream();
            var sr       = new StreamReader(stream);
            var content  = sr.ReadToEnd();

            return(content.ToString());
        }
Beispiel #29
0
        public async Task <ActionResult> Delete(int id, MakeVM model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                var make = await _repo.FindById(id);

                var isSuccess = await _repo.Delete(make);

                if (!isSuccess)
                {
                    ModelState.AddModelError("", "Something went wrong...");
                    return(View(model));
                }
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Beispiel #30
0
        public async Task <ActionResult> EditAsync([Bind(Include = "Id,Name,Abrv")] Guid id, MakeVM makeVM)
        {
            if (ModelState.IsValid)
            {
                var dest = Mapper.Map <VehicleMake>(makeVM);
                await service.EditAsync(id, dest);

                return(RedirectToAction(""));
            }
            return(View(makeVM));
        }