public ActionResult Add() { PartViewModel model = new PartViewModel(); model.Id = 0; return(View(model)); }
public ActionResult AddPart(PartViewModel part, int categoryId) { part.CategoryId = categoryId; _productService.SavePart(part.MapTo(new Domain.Model.Part())); return(RedirectToAction("Index")); }
public IActionResult AddPart(int idAssessment, PartViewModel part) { if (ModelState.IsValid && idAssessment > 0) { var _part = new Part() { Code = part.Code, Quantity = part.Quantity, MalfunctionType = part.MalfunctionType, IntensityType = part.IntensityType, UnitaryValue = part.UnitaryValue }; var result = _business.AddPart(new Assessment() { IdAssessment = idAssessment, IdCompany = User.GetClaim("CompanyId") }, _part); if (result.Sucess) { return(Ok()); } else { return(BadRequest(result.Error)); } } else { return(BadRequest(ModelState)); } }
public JsonResult GetPartLayouts(Guid partId) { var model = new PartViewModel(); var projectPart = _projectPartRepository.GetProjectPart(partId); if (projectPart != null) { var layouts = _projectPartRepository.GetProjectPartLayouts(partId); model.Layouts = new List <LayoutViewModel>(); foreach (var layout in layouts) { LayoutViewModel layoutModel = new ProjectPartLayoutConverter().ConvertToView(layout); model.Layouts.Add(layoutModel); } } else { var layouts = _partRepository.GetPartLayouts(partId); model.Layouts = new List <LayoutViewModel>(); foreach (var layout in layouts) { var layoutModel = new PartLayoutConverter().ConvertToView(layout); model.Layouts.Add(layoutModel); } } return(Json(model, JsonRequestBehavior.AllowGet)); }
public ActionResult Create(Part part) { if (ModelState.IsValid) { var viewModel = new PartViewModel { Id = part.Id, Name = part.Name, PartNumber = part.PartNumber, PartDescription = part.PartDescription, NumberInStock = part.NumberInStock, PartPrice = part.PartPrice }; return(View("New", viewModel)); } if (part.Id == 0) { _context.Parts.Add(part); } else { var partInDb = _context.Parts.Single(p => p.Id == part.Id); partInDb.Id = part.Id; partInDb.Name = part.Name; partInDb.PartNumber = part.PartNumber; partInDb.PartDescription = part.PartDescription; partInDb.NumberInStock = part.NumberInStock; partInDb.PartPrice = part.PartPrice; } _context.SaveChanges(); return(RedirectToAction("Index", "Parts")); }
public ActionResult CreateEdit(PartViewModel model) { try { if (ModelState.IsValid) { if (PartDataAccess.Update(model)) { return(Json(new { success = true, message = "Success" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = false, message = PartDataAccess.Message }, JsonRequestBehavior.AllowGet)); } } else { return(Json(new { success = false, message = "Lengkapi!" }, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { return(Json(new { success = false, ex.Message }, JsonRequestBehavior.AllowGet)); } }
// TODO: Make Click event handlers to Command event handlers, // if WPF has 'convinient' MVVM implementation on dialogs // and message box. private void EditPart_Click(object sender, RoutedEventArgs e) { ComputerPart part = (ComputerPart)lvComputerParts.SelectedItem; if (part == null) { // return if no selected item return; } try { PartDialog dialog = new PartDialog(part) { Owner = this }; dialog.ShowDialog(); if (dialog.DialogResult == true) { MainViewModel vm = (MainViewModel)DataContext; PartViewModel dialogVm = (PartViewModel)dialog.DataContext; vm.EditPart(part, dialogVm.GetPartDetail()); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); part = e.Parameter as PartViewModel; scrollOffsetKey = $"part-{part.Id}-scroll"; display = new DisplayRequest(); display.RequestActive(); }
public PartViewModel CreateNewPartObject() { var part = new PartViewModel(); part.PartCatalog = new PartCatalog(); part.Categories = RetrieveAllPartCategories(); return(part); }
public ActionResult Update(int?Id) { PartViewModel model = new PartViewModel(); model.Id = Id ?? 0; return(View(model)); }
public ActionResult EditPart(PartViewModel model) { var path = ""; var fullPath = "N/A"; var product = _productService.GetProduct(model.ProductId); var partCategory = product.Parts.FirstOrDefault(p => p.Category.Id == model.PartDetails.CategoryId); var incompatibleParts = new List <Part>(); if (model.PartDetails.Image.PartImageUpload != null) { var fileName = Path.GetFileName(model.PartDetails.Image.PartImageUpload.FileName); path = Url.Content(Path.Combine(Server.MapPath("~/Content/Images"), fileName)); model.PartDetails.Image.PartImageUpload.SaveAs(path); fullPath = @"~/Content/Images/" + fileName; } if (model.ExistingParts != null && model.ExistingParts.Count > 0) { foreach (var item in model.ExistingParts) { if (item.IsIncompatible) { incompatibleParts.Add(product.Parts.First(p => p.Id == item.Id)); } } } var part = product.Parts.SingleOrDefault(m => m.Id == model.PartDetails.Id); //part.IncompatibleParts = new List<Part>(); _productService.UpdateProduct(product, part); var sameCategory = product.Parts.Where(p => (p.Category.Id == part.Category.Id) && (p.Id != part.Id)).Select(p => p); incompatibleParts.AddRange(sameCategory); part.ImagePath = fullPath; part.LeadTime = model.PartDetails.LeadTime; part.Name = model.PartDetails.Name; part.Price = model.PartDetails.Price; part.StockKeepingUnit = model.PartDetails.StockKeepingUnit; part.IncompatibleParts = incompatibleParts; //product.Parts.Add(part); _productService.UpdateProduct(product); foreach (var p in part.IncompatibleParts) { p.IncompatibleParts.Add(part); } return(RedirectToAction("ProductPartList", new { id = product.Id })); }
public EditPartViewModel(PartViewModel part) : this() { m_part = part; m_isCustom = m_part.Custom; ApplyData(); }
public IActionResult Create(PartViewModel model) { if (!this.ModelState.IsValid || string.IsNullOrWhiteSpace(model.Name)) { return(this.Create()); } this._services.CreatePart(model.Name, model.Price, model.Quantity, model.Supplier); return(this.Redirect("/")); }
public ActionResult Edit(PartViewModel partViewModel) { if (ModelState.IsValid) { var existingPart = _partRepository.GetPartBy(partViewModel.PartId); var part = _mapperEngine.Map <Part>(partViewModel); _partRepository.Update(existingPart, part); return(RedirectToAction("Index")); } return(View(partViewModel)); }
public PartDialog(ComputerPart part = null) { InitializeComponent(); PartViewModel partViewModel = new PartViewModel(); if (part != null) { partViewModel.InitializeFields(part.Id); } DataContext = partViewModel; }
public ActionResult Create(PartViewModel partViewModel) { if (ModelState.IsValid) { partViewModel.PartId = Guid.NewGuid(); var car = _mapperEngine.Map <Part>(partViewModel); _partRepository.Save(car); return(RedirectToAction("Index")); } return(View(partViewModel)); }
public void SetPropertiesShouldSetModel() { var part = new Part(); var viewModel = new PartViewModel(part); viewModel.Barcode = "12345678"; viewModel.Position = 3; part.Barcode.Should().Be("12345678"); part.Position.Should().Be(3); }
public void ConstructorShouldInitalizeMember() { var part = new Part { Position = 1, Barcode = "12345678" }; var viewModel = new PartViewModel(part); viewModel.Position.Should().Be(1); viewModel.Barcode.Should().Be("12345678"); }
public void Indexer_EmptyType_ErrorMessage() { PartViewModel vm = new PartViewModel { Description = "some description", PartType = "", Condition = "some condition" }; string error = vm["PartType"]; Assert.AreEqual("Type is a mandatory field", error); }
public bool Add(PartViewModel cpu) { try { Connection.Query("pc.CreateCpu", new { cpu }, commandType: StoredProcedure); return(true); } catch (Exception ex) { throw ex; } }
public PartViewModel RetrievePartDataToUpdate(string partId) { //Look for part and return its data var partRetrievedFromDB = _partCatalogContext.Find(partId); var partToUpdateViewModel = new PartViewModel(); if (partRetrievedFromDB != null) { partToUpdateViewModel.PartCatalog = partRetrievedFromDB; partToUpdateViewModel.Categories = RetrieveAllPartCategories(); } return(partToUpdateViewModel); }
public ActionResult Save(PartViewModel partViewModel) { var partDto = Mapper.Map <PartDto>(partViewModel); if (!ModelState.IsValid) { partViewModel = new PartViewModel(); return(View("PartForm", partViewModel)); } if (partDto.Id == 0) { var path = fileManager.GeneratePictureName("/Files/Parts/"); partDto.PictureId = path; partService.Add(partDto); if (partViewModel.Picture.Upload != null) { partViewModel.Picture.Upload .SaveAs(Server.MapPath(path)); } } else { var pictureLink = partDto.PictureId; bool delete = true; if (pictureLink == null) { partDto.PictureId = fileManager.GeneratePictureName("/Files/Parts/"); delete = false; } partService.Edit(partDto); if (partViewModel.Picture.Upload != null) { if (delete) { var pathToPicture = Server.MapPath(pictureLink); if (fileManager.FileExists(pathToPicture)) { fileManager.Delete(pathToPicture); } } partViewModel.Picture.Upload .SaveAs(Server.MapPath(pictureLink)); } } return(RedirectToAction("Index", "Parts")); }
public IActionResult PartListPage() { PartViewModel partViewModel = new PartViewModel(); partViewModel.Cpu = _context.Cpu.ToList(); partViewModel.Cooler = _context.Cooler.ToList(); partViewModel.Motherboard = _context.Motherboard.ToList(); partViewModel.Ram = _context.Ram.ToList(); partViewModel.Storage = _context.Storage.ToList(); partViewModel.Gpu = _context.Gpu.ToList(); partViewModel.Psu = _context.Psu.ToList(); partViewModel.Case = _context.Case.ToList(); return(View(partViewModel)); }
public void Test1() { const string asm1Name = "Slider"; const string asm2Name = "Bed Assembly"; const string part1Name = "Base"; const string part2Name = "Bed"; const string part3Name = "Flange"; var doc = new AmlDocument(); var project = new ProjectViewModel(doc); doc.CaexDocument.CAEXFile.InstanceHierarchy.Insert(project.CaexObject as InstanceHierarchyType); var asm1 = new AssemblyViewModel(doc) { Name = asm1Name }; var asm2 = new AssemblyViewModel(doc) { Name = asm2Name }; var part1 = new PartViewModel(doc) { Name = part1Name }; var part2 = new PartViewModel(doc) { Name = part2Name }; var part3 = new PartViewModel(doc) { Name = part3Name }; project.Parts.Add(asm1); asm1.Parts.Add(asm2); asm1.Parts.Add(part1); asm2.Parts.Add(part2); asm2.Parts.Add(part3); var stream = doc.CaexDocument.SaveToStream(true); var caex = CAEXDocument.LoadFromStream(stream); var doc2 = new AmlDocument(caex); var ih = doc2.CaexDocument.CAEXFile.InstanceHierarchy.First; var vm = new ProjectViewModel(ih, doc2); }
/// <summary> /// Удалить контрол параметра в соотоветствии с выделенным в ComboBoxControlsToDelete. /// </summary> /// <param name="selectedIndex"></param> private void DeleteBarometerControlView(int selectedIndex) { PartViewModel pvm = mMainViewModel.PartWorkspace.CurrentPart; pvm.CurrentDeviceDetail = pvm.DeviceDetaills[selectedIndex]; if (pvm.DeleteDeviceDetailCommand.CanExecute(null)) { pvm.DeleteDeviceDetailCommand.Execute(null); RemoveAtBarometerControlView(selectedIndex); } tslDeleteBarometer.Enabled = false; ComboBoxControlsToDelete.ComboBoxToDelete.ComboBoxControlsToDelete.Text = string.Empty; }
public void Indexer_AllFilledUp_NoErrorMessage() { PartViewModel vm = new PartViewModel { Description = "some description", PartType = "some part", Condition = "some condition" }; string error = vm["Type"]; Assert.AreEqual("", error); error = vm["Part"]; Assert.AreEqual("", error); error = vm["Condition"]; Assert.AreEqual("", error); }
public ActionResult Edit(PartViewModel part, string Id) { //if errors found return to view, otherwise insert into DB if (!ModelState.IsValid) { //Populate Categories DropDownList part.Categories = _partCatalogService.RetrieveAllPartCategories(); return(View(part)); } else { _partCatalogService.UpdatePartData(part.PartCatalog, Id); //Once part updated then return to display list of parts return(RedirectToAction("Index")); } }
public static bool Update(PartViewModel model) { bool result = true; try { using (var db = new FleetManagementContext()) { if (model.Id == 0) { MstPart part = new MstPart(); part.PartId = model.PartId; part.Description = model.Description; part.Price = model.Price; part.IsActive = model.IsActive; part.CreatedBy = model.CreatedBy; part.Created = model.Created; part.ModifiedBy = model.ModifiedBy; part.Modified = model.Modified; db.MstParts.Add(part); db.SaveChanges(); } else { MstPart part = db.MstParts.Where(o => o.Id == model.Id).FirstOrDefault(); if (part != null) { part.PartId = model.PartId; part.Description = model.Description; part.Price = model.Price; part.IsActive = model.IsActive; part.CreatedBy = model.CreatedBy; part.Created = model.Created; part.ModifiedBy = model.ModifiedBy; part.Modified = model.Modified; db.SaveChanges(); } } } } catch (Exception ex) { Message = ex.Message; result = false; } return(result); }
public ActionResult EditPart(int productId, int partId) { var product = _productService.GetProduct(productId); var part = product.Parts.SingleOrDefault(p => p.Id == partId); var viewModel = new PartViewModel() { ExistingParts = product.Parts.Where(p => p.Id != part.Id).Select(p => new PartModel(p) { IsIncompatible = part.IncompatibleParts.Contains(p) }).ToList(), ProductId = productId, PartDetails = new PartModel(part) }; return(View(viewModel)); }
//[HttpPost] //public ActionResult Upload(HttpPostedFileBase photo) //{ // var path = ""; // if(photo != null && photo.ContentLength > 0) // { // var fileName = Path.GetFileName(photo.FileName); // path = Url.Content(Path.Combine(Server.MapPath("~/Content/Images"), fileName)); // photo.SaveAs(path); // } // return RedirectToAction("CreateProduct"); //} public ActionResult AddPart(int id) { var product = _productService.GetProduct(id); var viewModel = new PartViewModel() { Categories = _productService.GetAllPartCategoriesByProduct(product) .Select(c => new SelectListItem() { Value = c.Id.ToString(), Text = c.Name }), ExistingParts = product.Parts.Select(p => new PartModel(p)).ToList(), ProductId = id }; return(View(viewModel)); }
public JsonResult GetPartById(int Id) { PartViewModel model = new PartViewModel(); Data.Models.Part partobj = this._partService.GetForId(Id); if (partobj != null) { //model.SiteId = 1; //model.MachineId = partobj.MachineId; //model.PlantId = partobj.PlantId; //model.LineId = partobj.LineId; model.Name = partobj.Name; model.Description = partobj.Description; } return(Json(model, JsonRequestBehavior.AllowGet)); }