public IActionResult AddEdit(String ID, String ManufactName) { var model = new ManufacturerViewModel(HttpContext); model.manufacturers = dbContext.Manufacturers.ToList(); try { var mc = dbContext.Manufacturers.Find(ID); if (mc != null) { mc.ID = ID; mc.ManufactName = ManufactName; dbContext.Manufacturers.Update(mc); dbContext.SaveChanges(); return(RedirectToAction("Index", model)); } else { var mc2 = new Manufacturer(); mc2.ID = ID; mc2.ManufactName = ManufactName; dbContext.Manufacturers.Add(mc2); dbContext.SaveChanges(); return(RedirectToAction("index", model)); } } catch (Exception e) { Console.WriteLine(e); } return(View("index", model)); }
public JsonResult GETJSON() { var model = new ManufacturerViewModel(HttpContext); model.manufacturers = dbContext.Manufacturers.ToList(); return(Json(model)); }
public IActionResult Index() { var model = new ManufacturerViewModel(HttpContext); model.manufacturers = dbContext.Manufacturers.ToList(); return(View("Index", model)); }
public async Task <IActionResult> Put([FromRoute] int id, [FromBody] ManufacturerViewModel manufacturer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != manufacturer.ManufacturerId) { return(BadRequest()); } try { await _repostory.UpdateManufacturer(manufacturer); return(CreatedAtAction("GetManufacturer", new { id = manufacturer.ManufacturerId }, manufacturer)); } catch (DbUpdateConcurrencyException) { if (!ManufacturerExists(id)) { return(NotFound()); } throw; } }
public ActionResult Create() { ManufacturerViewModel p = new ManufacturerViewModel(); p.IsActive = true; return(View("Create", p)); }
public ActionResult Destroy([DataSourceRequest] DataSourceRequest request, ManufacturerViewModel model) { if (model != null && ModelState.IsValid) { var manufacturerToDelete = this.Data.Manufacturers.GetById(model.Id); if (manufacturerToDelete == null) { ModelState.AddModelError( "alert", "An unexpected error has occurred. The manufacturer you want to delet was not found..."); return(Json(ModelState.ToDataSourceResult())); } foreach (var laptop in manufacturerToDelete.Laptops.ToList()) { foreach (var vote in laptop.Votes.ToList()) { this.Data.Votes.Delete(vote); } foreach (var comment in laptop.Comments.ToList()) { this.Data.Comments.Delete(comment); } this.Data.Laptops.Delete(laptop); } this.Data.Manufacturers.Delete(manufacturerToDelete); this.Data.SaveChanges(); } return(Json(new object())); }
public string DeleteManufacturer(ManufacturerViewModel ManufacturerObj) { if (!ModelState.IsValid) { if (ManufacturerObj.ID != 0) { try { OperationsStatusViewModel operationsStatus = new OperationsStatusViewModel(); OperationsStatusViewModel OperationsStatusViewModelObj = Mapper.Map <OperationsStatus, OperationsStatusViewModel>(_masterBusiness.DeleteManufacturer(ManufacturerObj.ID)); if (OperationsStatusViewModelObj.StatusCode == 1) { return(JsonConvert.SerializeObject(new { Result = "OK", Record = OperationsStatusViewModelObj })); } else { return(JsonConvert.SerializeObject(new { Result = "Error", Record = OperationsStatusViewModelObj })); } } catch (Exception ex) { return(JsonConvert.SerializeObject(new { Result = "ERROR", Message = ex.Message })); } } } return(JsonConvert.SerializeObject(new { Result = "ERROR", Message = "Please Select Manufacturer" })); }
public ActionResult Create([DataSourceRequest] DataSourceRequest request, ManufacturerViewModel model) { var results = new List <ManufacturerViewModel>(); if (model != null && ModelState.IsValid) { var manufacturerNameLowerCase = model.Name.Trim().ToLower(); if (this.Data.Manufacturers.All().Any(m => m.Name.ToLower() == manufacturerNameLowerCase)) { ModelState.AddModelError("Name", "There's already a manufacturer with this name!"); return(Json(ModelState.ToDataSourceResult())); } var newManufacturer = new Manufacturer() { Name = model.Name.Trim() }; this.Data.Manufacturers.Add(newManufacturer); this.Data.SaveChanges(); model.Id = newManufacturer.Id; results.Add(model); } return(Json(results.ToDataSourceResult(request))); }
public ActionResult Update([DataSourceRequest] DataSourceRequest request, ManufacturerViewModel model) { if (model != null && ModelState.IsValid) { var manufacturerToUpdate = this.Data.Manufacturers.GetById(model.Id); if (manufacturerToUpdate == null) { ModelState.AddModelError( "alert", "An unexpected error has occurred. The manufacturer you want to update was not found..."); return(Json(ModelState.ToDataSourceResult())); } var manufacturerNameLowerCase = model.Name.Trim().ToLower(); if (manufacturerToUpdate.Name.ToLower() != manufacturerNameLowerCase) { if (this.Data.Manufacturers.All().Any(m => m.Name.ToLower() == manufacturerNameLowerCase)) { ModelState.AddModelError("Name", "There's already a manufacturer with this name!"); } else { manufacturerToUpdate.Name = model.Name.Trim(); this.Data.SaveChanges(); } } if (ModelState.IsValid) { return(Json(new object())); } } return(Json(ModelState.ToDataSourceResult())); }
public async Task <ActionResult> SaveModify(ManufacturerViewModel model) { using (ManufacturerServiceClient client = new ManufacturerServiceClient()) { MethodReturnResult <Manufacturer> result = await client.GetAsync(model.Code); if (result.Code == 0) { result.Data.Name = model.Name; result.Data.NickName = model.NickName; result.Data.Description = model.Description; result.Data.Editor = User.Identity.Name; result.Data.EditTime = DateTime.Now; MethodReturnResult rst = await client.ModifyAsync(result.Data); if (rst.Code == 0) { rst.Message = string.Format(FMMResources.StringResource.Manufacturer_SaveModify_Success , model.Code); } return(Json(rst)); } return(Json(result)); } }
// // GET: /FMM/Manufacturer/Detail public async Task <ActionResult> Detail(string key) { using (ManufacturerServiceClient client = new ManufacturerServiceClient()) { MethodReturnResult <Manufacturer> result = await client.GetAsync(key); if (result.Code == 0) { ManufacturerViewModel viewModel = new ManufacturerViewModel() { Name = result.Data.Name, Code = result.Data.Key, NickName = result.Data.NickName, CreateTime = result.Data.CreateTime, Creator = result.Data.Creator, Description = result.Data.Description, Editor = result.Data.Editor, EditTime = result.Data.EditTime }; return(PartialView("_InfoPartial", viewModel)); } else { ModelState.AddModelError("", result.Message); } } return(PartialView("_InfoPartial")); }
// // POST: /FMM/Manufacturer/Save //[HttpPost] //[ValidateAntiForgeryToken] public async Task <ActionResult> Save(ManufacturerViewModel model) { using (ManufacturerServiceClient client = new ManufacturerServiceClient()) { Manufacturer obj = new Manufacturer() { Key = model.Code.ToString().Trim(), //新增供应商代码不可包含空格 Name = model.Name, //由于现有错误,供应商名称可以有空格 NickName = model.NickName, Description = model.Description, Editor = User.Identity.Name, EditTime = DateTime.Now, CreateTime = DateTime.Now, Creator = User.Identity.Name }; MethodReturnResult rst = await client.AddAsync(obj); if (rst.Code == 0) { rst.Message = string.Format(FMMResources.StringResource.Manufacturer_Save_Success , model.Code); } return(Json(rst)); } }
public async Task Update(ManufacturerViewModel viewModel) { var model = await _context.Manufacturers.FindAsync(viewModel.Id); model.ManufacturerName = viewModel.ManufacturerName; await _context.SaveChangesAsync(); }
public IActionResult SaveDelivery(ManufacturerViewModel viewModel) { try { viewModel.Token = HttpContext.Session.GetString(AppResource.Token); var response = _httpClientProvider.PostDeliveryAsJsonAsync(viewModel); if (response.StatusCode == HttpStatusCode.Unauthorized) { TempData[AppResource.ErrorMessage] = AppResource.Unauthorized; return(RedirectToAction(AppResource.SaveManufacturerAction)); } if (response.IsSuccessStatusCode) { TempData[AppResource.ErrorMessage] = AppResource.SaveSuccessMessageText; return(RedirectToAction(AppResource.SaveManufacturerAction)); } TempData[AppResource.ErrorMessage] = AppResource.SaveErrorMessageText; return(RedirectToAction(AppResource.SaveManufacturerAction)); } catch (Exception ex) { _logger.LogError(ex.ToString()); return(View()); } }
public static bool EditManufacturer(ManufacturerViewModel model) { if (model.Id > 0) { try { IQueryable <Manufacturer> manufacturer = identityASPdb.Manufacturer.Where(x => x.Id == model.Id); if (manufacturer != null) { foreach (var item in manufacturer) { item.Id = model.Id; item.Name = model.Name; item.Location = model.Location; item.Manager = model.Manager; item.Telephone = model.Telephone; item.Fax = model.Fax; item.Email = model.Email; item.Mobile = model.Mobile; identityASPdb.Entry(item).State = EntityState.Modified; } identityASPdb.SaveChanges(); result = true; } } catch (Exception) { throw; } } return(result); }
public JsonResult Delete(String ID) { var model = new ManufacturerViewModel(HttpContext); model.manufacturers = dbContext.Manufacturers.ToList(); try { var mc = dbContext.Manufacturers.Find(ID); if (mc != null) { dbContext.Manufacturers.Remove(mc); dbContext.SaveChanges(); return(this.GETJSON()); } else { return(this.GETJSON()); } } catch (Exception) { return(this.GETJSON()); } }
public ManufacturerViewModel GetById(int id) { var manuf = _dbManuf.GetById(id); var manufModel = new ManufacturerViewModel { Id = manuf.Id, Name = manuf.Name, CarsModel = manuf.CarsModel.Select(x => new CarViewModel { Id = x.Id, Model = x.Model, ManufacturerId = x.ManufacturerId, Details = x.Details.Select(y => new DetailViewModel { Id = y.Id, Cost = y.Cost, Type = (DetailTypeEnum)y.Type, ManufacturerId = y.ManufacturerId, }), }), DetailsModel = manuf.DetailsModel.Select(x => new DetailViewModel { Id = x.Id, Name = x.Name, Cost = x.Cost, Type = (DetailTypeEnum)x.Type, ManufacturerId = x.ManufacturerId }) }; return(manufModel); }
public ActionResult SaveEdit(ManufacturerViewModel manufacturerViewModel) { manufacturerViewModel.operationType = OperationType.Edit; if (ModelState.IsValid) { _manufacturerModelFactory.saveManufacturer(manufacturerViewModel); if (manufacturerViewModel.operationStatus == OperationStatus.Error) { if (manufacturerViewModel.ecvRuleViolation != null && manufacturerViewModel.ecvRuleViolation.Count() > 0) //if business and validation rules violations { foreach (var _propertyError in manufacturerViewModel.ecvRuleViolation) { //--Add error property level ModelState.AddModelError("manufacturerModel." + _propertyError._propertyName, _propertyError._errorMessage); } } else // else only single error { ModelState.AddModelError(string.Empty, manufacturerViewModel.OperationMessage); } return(View("ManufacturerForm", manufacturerViewModel)); } TempData["message"] = string.Format("Manufacturer \"{0}\" has been updated.", manufacturerViewModel.manufacturerModel.Name); return(RedirectToAction("List")); } else { return(View("ManufacturerForm", manufacturerViewModel)); } }
public ManufacturerViewModel getManufacturerVM(int manufacturerId) { //Get Manufacturer var manufacturer = _mnfService.GetEntityById(manufacturerId); //_unitOfWork.manufacturerRepository.Get(manufacturerId); var manufacturerViewModel = new ManufacturerViewModel { manufacturerModel = new ManufacturerModel() }; if (manufacturer == null) { manufacturerViewModel = null; return(manufacturerViewModel); } //Prepare Manufacturere Model foreach (var propDest in manufacturerViewModel.manufacturerModel.GetType().GetProperties()) { //Find property in source based on destination name var propSrc = manufacturer.GetType().GetProperty(propDest.Name); if (propSrc != null) { //Get value from source and assign it to destination propDest.SetValue(manufacturerViewModel.manufacturerModel, propSrc.GetValue(manufacturer)); } } return(manufacturerViewModel); }
public ManufacturerViewModel saveManufacturer(ManufacturerViewModel manufacturerViewModel) { //throw new NotImplementedException(); ManufacturerDTO manufacturerDTO = new ManufacturerDTO(); var manufacturerMapper = new ecvMapper <ManufacturerModel, ManufacturerDTO>(); manufacturerDTO = manufacturerMapper.CreateMappedObject(manufacturerViewModel.manufacturerModel); var _manufacturerServiceStatus = _mnfService.SaveEntity(manufacturerDTO); if (_manufacturerServiceStatus.operationStatus == OperationStatus.Error) { manufacturerViewModel.operationStatus = OperationStatus.Error; if (!string.IsNullOrEmpty(_manufacturerServiceStatus.OperationMessage)) { manufacturerViewModel.OperationMessage = _manufacturerServiceStatus.OperationMessage; } manufacturerViewModel.ecvRuleViolation = _manufacturerServiceStatus.ecvRuleViolation; } else { manufacturerViewModel.operationStatus = OperationStatus.Success; if (!string.IsNullOrEmpty(_manufacturerServiceStatus.OperationMessage)) { manufacturerViewModel.OperationMessage = _manufacturerServiceStatus.OperationMessage; } manufacturerViewModel.ecvRuleViolation = _manufacturerServiceStatus.ecvRuleViolation; } return(manufacturerViewModel); }
public void SaveManufacturer(ManufacturerViewModel model) { var manufact = new Manufacturer(); if (model.ManufactId > 0) { manufact = db.Manufacturers.FirstOrDefault(m => m.ManufacturerId == model.ManufactId); } manufact.Name = model.Name; manufact.IsActive = true; manufact.Phone = model.Phone; manufact.Address = model.Address; manufact.City = model.City; manufact.Country = model.Country; manufact.Alias = model.Alias; if (model.ManufactId == 0) { manufact.CreatedBy = (int)GetLoggedInUserId(); manufact.CreatedOn = DateTime.UtcNow; db.Manufacturers.Add(manufact); } else { manufact.UpdatedBy = (int)GetLoggedInUserId(); manufact.UpdatedOn = DateTime.UtcNow; db.Entry(manufact).State = System.Data.Entity.EntityState.Modified; } db.SaveChanges(); }
//[ValidateAntiForgeryToken] public ActionResult Edit(ManufacturerViewModel model) { var manufacturer = _manufacturerService.GetManufacturer(model.Id); if (manufacturer == null) { return(NotFound()); } if (ModelState.IsValid) { manufacturer.Name = model.Name; manufacturer.Description = model.Description; manufacturer.CountryId = model.CountryId; var result = _manufacturerService.UpdateManufacturer(manufacturer); model.Id = manufacturer.Id; if (result.Succedeed) { return(Json(model)); } return(NotFound(result)); } return(PartialView(model)); }
public ManufacturerViewModel GetById(int Id) { var model = service.GetById(Id); var manufacturerModel = new ManufacturerViewModel { Id = model.Id, Name = model.Name, CarsModel = model.CarsModel.Select(x => new CarViewModel { Id = x.Id, Name = x.Name, Details = x.Details.Select(y => new DetailViewModel { Id = y.Id, Name = y.Name, CarID = y.CarID, Price = y.Price }) }), DetailsModel = model.DetailsModel.Select(z => new DetailViewModel { Id = z.Id, Name = z.Name, CarID = z.CarID, Price = z.Price }) }; return(manufacturerModel); }
public IActionResult Create(ManufacturerViewModel model) { if (ModelState.IsValid) { var man = new Manufacturer { ManufacturerName = model.Name, About = model.About, ImagePath = model.ImagePath }; var x = _databaseContext.Manufacturer.FirstOrDefault(g => g.ManufacturerName == man.ManufacturerName); if (x != null) { TempData[Constants.Message] = $"Proizvođač tog imena već postoji.\n"; TempData[Constants.ErrorOccurred] = true; return(View("Add", model)); } _databaseContext.Manufacturer.Add(man); TempData["Success"] = true; _databaseContext.SaveChanges(); TempData[Constants.Message] = $"Proizvođač je dodan"; TempData[Constants.ErrorOccurred] = false; return(RedirectToAction(nameof(Index))); } return(View("Add", model)); }
public bool?Update(int key, ManufacturerViewModel model, IDataSourceError error) { var manufacturer = this.SingleOrDefault(key); if (manufacturer == null) { return(null); } manufacturer.Name = model.Name; manufacturer.Address = model.Address; manufacturer.ContactPerson = model.ContactPerson; manufacturer.ContactPersonPhone = model.ContactPersonPhone; manufacturer.Phone = model.Phone; manufacturer.Fax = model.Fax; bool result = false; try { this.DbContext.SaveChanges(); result = true; } catch { } return(result); }
public bool Create(ManufacturerViewModel model, IDataSourceError error) { var manufacturer = new Manufacturer { Name = model.Name, Address = model.Address, ContactPerson = model.ContactPerson, ContactPersonPhone = model.ContactPersonPhone, Phone = model.Phone, Fax = model.Fax }; this.DbContext.Manufacturers.Add(manufacturer); var result = false; try { this.DbContext.SaveChanges(); model.ManufacturerId = manufacturer.ManufacturerId; result = true; } catch { } return(result); }
public async Task <ActionResult> Update(int id, ManufacturerViewModel model) { try { var manufacturer = await _makeRepo.GetManufacturerById(id); if (manufacturer == null) { return(NotFound($"Kunde inte hitta någon tillverkare med id: {id}")); } manufacturer.Name = model.Name; _makeRepo.Update(manufacturer); if (await _makeRepo.SaveAllAsync()) { return(NoContent()); } return(StatusCode(500, "Det gick inte att uppdatera tillverkaren")); } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }
public async Task <ActionResult> Add(ManufacturerViewModel model) { try { var manufacturer = await _makeRepo.GetManufacturerByName(model.Name); if (manufacturer != null) { return(BadRequest("Tillverkaren finns redan i systemet!")); } var make = new Make { Name = model.Name }; _makeRepo.Add(make); if (await _makeRepo.SaveAllAsync()) { return(StatusCode(201, make)); } return(StatusCode(500, "Det gick inte att spara ner tillverkaren")); } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }
public async Task <IEnumerable <ManufacturerViewModel> > GetAllManufacturerAsync() { _logger.LogInformation("GetAllManufacturerAsync called."); var manu = await _manufacturerRepository.ListAllAsync(); var manViewList = new List <ManufacturerViewModel>(); foreach (var manufacturer in manu) { var manView = new ManufacturerViewModel { Id = manufacturer.Id, Name = manufacturer.Name, Url = manufacturer.Url, SupportUrl = manufacturer.SupportUrl, SupportEmail = manufacturer.SupportEmail, SupportPhone = manufacturer.SupportPhone, Image = manufacturer.Image, CreatedAt = manufacturer.CreatedAt, UpdatedAt = manufacturer.UpdatedAt, UpdatedBy = manufacturer.UpdatedBy, DeletedAt = manufacturer.DeletedAt }; manViewList.Add(manView); } return(manViewList); }
/// <summary> /// Post delivery details to api. /// </summary> /// <param name="model">View model of Manufacturer to be posted.</param> /// <returns></returns> public HttpResponseMessage PostDeliveryAsJsonAsync(ManufacturerViewModel model) { using (var client = _httpClient) { using (var multiPartContent = new MultipartFormDataContent()) { client.BaseAddress = new Uri(_httpConfiguartion.Value.BaseUrl.EndsWith("/") ? _httpConfiguartion.Value.BaseUrl : _httpConfiguartion.Value.BaseUrl + "/"); client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", model.Token); try { var responseTask = client.PostAsJsonAsync("SaveDelivery/", model); responseTask.Wait(); return(responseTask.Result); } catch (Exception ex) { _logger.LogError(ex.ToString()); return(new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new StringContent("{\"message\":\"Something went wrong.\"}", System.Text.Encoding.UTF8, "application/json") }); } } } }
public async Task<ActionResult> Submit(ManufacturerViewModel manufacturer) { if (ModelState.IsValid) { unitOfWork.ManufacturerRepository.Save(manufacturer.DomainManufacturer); await unitOfWork.CompleteAsync(); return RedirectToAction("Index"); } return View("Edit", manufacturer); }
public CarViewModel(Car domainCar) { this.domainCar = domainCar; Manufacturer = new ManufacturerViewModel(domainCar.Manufacturer); }