//To Add New Item public ActionResult AddItemToDb(AddItemViewModel itemViewModel) { if (!ModelState.IsValid) { itemViewModel.Categories = _context.Categories.ToList(); return(View("AddItemInView", itemViewModel)); } _context.Items.Add(itemViewModel.Item); _context.SaveChanges(); return(View(itemViewModel.Item)); }
public void GetStockTypesResultTwoStockType() { var target = new AddItemViewModel(null, null); var actual = target.StockTypes; Assert.IsNotNull(actual); var actualList = actual.ToList(); Assert.AreEqual(2, actualList.Count); Assert.IsTrue(actualList.Contains(StockType.Equity)); Assert.IsTrue(actualList.Contains(StockType.Bond)); }
public async Task <IActionResult> AddProduct(AddItemViewModel model) {//aqui me muestra los productos y que me agregue un items if (this.ModelState.IsValid) { await this.orderRepository.AddItemToOrderAsync(model, this.User.Identity.Name); return(this.RedirectToAction("Create")); } return(this.View(model)); }
public IActionResult AddProduct() { var model = new AddItemViewModel { Quantity = 1, // Método para traer todos los Productos para cargar el Combo Products = this.productRepository.GetComboProducts() }; return(View(model)); }
public async Task <IActionResult> AddProduct(AddItemViewModel model) { if (this.ModelState.IsValid) { await this.orderRepository.AddItemToOrderAsync(model, this.User.Identity.Name); return(this.RedirectToAction("Create")); } return(this.View(model)); }
public async Task<ActionResult> Submit(AddItemViewModel model) { await MvcApplication.Bus.Publish<CartItemAdded>(new { UserName = model.UserName ?? "Unknown", Timestamp = DateTime.UtcNow, }); return View("Index"); }
public IActionResult ChooseItem(int id) { var model = new AddItemViewModel { Quantity = 1, ItemId = id, Items = _itemRepository.GetComboItems() }; return(View(model)); }
public async Task <IActionResult> AddVehicle(AddItemViewModel model) { if (this.ModelState.IsValid) { await _appointmentRepository.AddItemToAppointmentAsync(model, this.User.Identity.Name); return(this.RedirectToAction("Create")); } return(View(model)); }
public ActionResult AddProduct() { var model = new AddItemViewModel() { //aqui armoi la lsita del combo box de products: Products = productRepository.GetComboProducts(), Quantity = 1, }; return(View(model)); }
public NewItemPage() { InitializeComponent(); Item = new Post { Text = "Item name", Description = "This is an item description." }; BindingContext = viewModel = new AddItemViewModel(); TakePicture(); }
public AddItemViewModel GetShopingModel(string productId) { if (string.IsNullOrEmpty(productId)) { throw new ArgumentNullException(); } var product = this.productRepository .All() .Where(x => x.Id == productId) .FirstOrDefault(); if (product is null) { throw new Exception(); } var model = new AddItemViewModel() { Product = new DetailsProductAddItemVM() { Id = product.Id, Name = product.Name, Description = product.Description, ImageUrl = product.ImageUrl != null ? product.ImageUrl : GlobalConstants.DefaultProductImage, HasExtras = product.HasExtras, Allergens = product.Allergens .Select(c => new DetailsAllergenViewModel() { Id = c.AllergenId, Name = c.Allergen.Name, ImageUrl = c.Allergen.ImageUrl, }).ToList(), Sizes = product.Sizes .Select(c => new ProductSizeViewModel() { SizeId = c.Id, SizeName = c.SizeName, Price = c.Price, Weight = c.Weight, MaxProductsInPackage = c.MaxProductsInPackage, PackagePrice = c.Package.Price, }).ToList(), }, }; if (model.Product.HasExtras) { model.Extras = this.extrasService.All(isDeleted: false).ToList(); } return(model); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); if (ViewModel == null) { ViewModel = new AddItemViewModel(); } title = FindViewById <EditText>(Resource.Id.title); description = FindViewById <EditText>(Resource.Id.description); }
public async Task <bool> ConfirmOrderFromAPPAsync(List <OrderDetailTemp> model) { var user = await this.userHelper.GetUserByEmailAsync(model.Select(u => u.User.UserName).First()); if (user == null) { return(false); } foreach (OrderDetailTemp m in model) { var tmp = new AddItemViewModel { ProductId = m.Product.Id, Quantity = m.Quantity }; await AddItemToOrderAsync(tmp, user.ToString()); } var orderTmps = await this.context.OrderDetailTemps .Include(o => o.Product) .Where(o => o.User == user) .ToListAsync(); if (orderTmps == null || orderTmps.Count == 0) { return(false); } var details = model.Select(o => new OrderDetail { Price = o.Price, Product = o.Product, Quantity = o.Quantity }).ToList(); var order = new Order { OrderDate = DateTime.UtcNow, User = user, Items = details, }; this.context.Orders.Add(order); this.context.OrderDetailTemps.RemoveRange(orderTmps); await this.context.SaveChangesAsync(); return(true); }
public ActionResult AddProduct(AddItemViewModel model) { using (var db = new OnlineShopDbContext()) { var item = new Item { Desciption = model.Description, Price = model.Price, ShowOnSite = true, SubCategoryId = model.SubCatId, Title = model.Title }; db.Items.Add(item); db.SaveChanges(); foreach (var color in model.Colors) { var itemColor = new ItemColor { ColorId = color, ItemId = item.Id }; db.ItemColors.Add(itemColor); } foreach (var size in model.Sizes) { var itemSize = new ItemSize { SizeId = size, ItemId = item.Id }; db.ItemSizes.Add(itemSize); } var link1 = new Image { IsMain = true, ItemId = item.Id, Link = model.Link1, }; var link2 = new Image { IsMain = false, ItemId = item.Id, Link = model.Link2, }; var link3 = new Image { IsMain = false, ItemId = item.Id, Link = model.Link3, }; var link4 = new Image { IsMain = false, ItemId = item.Id, Link = model.Link4, }; db.Images.Add(link1); db.Images.Add(link2); db.Images.Add(link3); db.Images.Add(link4); db.SaveChanges(); return(Json(item.Id, JsonRequestBehavior.AllowGet)); } }
public async Task <IActionResult> Post([FromBody] AddItemViewModel model) { if (model == null) { return(BadRequest()); } var parentItem = await _itemGroupRepo.GetAsync(model.ItemGroupId); if (parentItem == null) { return(NotFound(Resources.Items.ItemResource.ItemGroupNotFound)); } var unit = await _unitRepo.GetAsync(model.UnitId); if (unit == null) { return(NotFound(Resources.Items.ItemResource.UnitNotFound)); } if (await _itemRepo.IsExistCodeAsync(model.Code)) { ModelState.AddModelError("Code", Resources.Global.Common.ThisCodeExist); } if (await _itemRepo.IsExistNameAsync(model.Name)) { ModelState.AddModelError("Name", Resources.Global.Common.ThisNameExist); } if (!string.IsNullOrWhiteSpace(model.UnitBarcode) && await _itemUnitRepo.IsExistCodeAsync(model.UnitBarcode)) { ModelState.AddModelError("UnitBarcode", Resources.Items.ItemResource.ThisBarCodeExist); } if (!ModelState.IsValid) { return(BadRequest(ModelState.GetWithErrorsKey())); } var item = new Item(model.Name, model.Code, model.Type, parentItem.Id, true, model.Note, unit.Id, model.UnitBarcode); var affectedRows = await _itemRepo.AddAsync(item); if (affectedRows > 0) { var viewModel = AutoMapper.Mapper.Map <ItemViewModel>(item); return(CreatedAtRoute("GetItem", new { id = item.Number }, viewModel)); } return(BadRequest()); }
public void CancellingWillNavigateBack() { var offlineTaskService = A.Fake <IOfflineTaskService>(); var loggingService = A.Fake <ILoggingService>(); var database = TestsHelper.CreateFakeDatabase(); var navigationService = A.Fake <INavigationService>(); var viewModel = new AddItemViewModel(offlineTaskService, loggingService, database, navigationService); viewModel.CancelCommand.Execute(null); A.CallTo(() => navigationService.GoBack()).MustHaveHappened(); }
public IActionResult Add() { var categories = _categoryService.GetAll(); var brands = _brandService.GetBrandsByCategoryId(categories.FirstOrDefault().CategoryId); var model = new AddItemViewModel() { Brands = brands.ToSelectList(), Categories = categories.ToSelectList() }; return(PartialView("_Add", model)); }
public void AddItem_ShouldSetViewItemProperties_IfModelIsValid() { // Arrange var adminController = new AdminController(this.itemServiceMock.Object, this.mappingServiceMock.Object, this.imageProviderMock.Object); var viewModel = new AddItemViewModel(); // Act adminController.AddItem(viewModel); // Assert Assert.AreEqual(viewModel.IsDeleted, false); Assert.AreEqual(viewModel.Discount, 0); }
protected override void OnAppearing() { base.OnAppearing(); ViewModel = new AddItemViewModel(App.DataRepository); ViewModel.ItemAdded += async(s, e) => { await Navigation.PopAsync(); }; ItemEntry.Focus(); }
public void AddItem_ShouldRedirectToAdminPanel() { //Arange var adminController = new AdminController(this.itemServiceMock.Object, this.mappingServiceMock.Object, this.imageProviderMock.Object); var addItemViewModel = new AddItemViewModel(); //Act var redirectResult = adminController.AddItem(addItemViewModel) as RedirectResult; //Assert Assert.IsNotNull(redirectResult); Assert.AreEqual(ServerConstants.AdminPanelRedirectUrl, redirectResult.Url); }
public async Task <IActionResult> AddItem(string displacementId, string WhereTo) { User user = await database.Users.FirstOrDefaultAsync(r => r.Username == User.Identity.Name); var room = await database.Rooms.FirstOrDefaultAsync(r => r.Name == WhereTo); var model = new AddItemViewModel { DisplacementId = Int32.Parse(displacementId), RoomSelectId = room.Id }; return(View(model)); }
public async Task AddItemToOrderAsync(AddItemViewModel model, string userName, bool isReSeller) { var user = await _userHelper.GetUserByEmailAsync(userName); if (user == null) { return; } var product = await _context.Products.FindAsync(model.ProductId); if (product == null) { return; } float newPrice; if (isReSeller) { newPrice = product.Price * 0.8f; } else { newPrice = product.Price; } var orderDetailTemp = await _context.OrderDetailsTemp .Where(odt => odt.User == user && odt.Product == product) .FirstOrDefaultAsync(); if (orderDetailTemp == null) { orderDetailTemp = new OrderDetailTemp { Price = newPrice, Product = product, Quantity = model.Quantity, User = user }; _context.OrderDetailsTemp.Add(orderDetailTemp); } else { orderDetailTemp.Quantity += model.Quantity; _context.OrderDetailsTemp.Update(orderDetailTemp); } await _context.SaveChangesAsync(); }
private bool SaveMenuItem(AddItemViewModel addItemViewModel) { bool isSuccess = false; ItemBM itemBM = Mapper.Map <ItemBM>(addItemViewModel.ItemDetail); ItemImageBM itemImageBM = new ItemImageBM { ImageName = addItemViewModel.ItemDetail.File.FileName, ImageData = ReduceSizeOfImgFileFromPostedFile(addItemViewModel.ItemDetail.File) }; itemImageBM.ImageSize = itemImageBM.ImageData.Length; isSuccess = _adminBusinessClass.SaveNewItem(itemBM, itemImageBM); return(isSuccess); }
public IActionResult AddItem(AddItemViewModel addItemVM) { var newItem = new Item { Name = addItemVM.NewItem.Name, Quantity = addItemVM.NewItem.Quantity, Price = addItemVM.NewItem.Price, UserId = new Guid(User.FindFirstValue("UserId")) }; _operationDb.CreateModel(newItem); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> AddItem(int Id) { int maxitems = 1000; if (Id != null) { User currentuser = null; User user = null; if (User.Identity.Name != null) { currentuser = await _userManager.FindByNameAsync(User.Identity.Name); } Collection collection = await db.Collections.FindAsync(Id); if (collection != null) { user = await _userManager.FindByNameAsync(collection.UserName); } if (collection != null && currentuser != null && user.Role == "user" && collection.ItemCount < maxitems) { if (currentuser.UserName == collection.UserName || currentuser.Role == "admin" || currentuser.Role == "moderator") { AddItemViewModel model = new AddItemViewModel { CollectionId = collection.Id, UserName = collection.UserName, ItemName = null, Likes = 0, }; return(View(model)); } } else if (collection != null && currentuser != null && collection.ItemCount < maxitems) { if (currentuser.UserName == collection.UserName || currentuser.Role == "admin") { AddItemViewModel model = new AddItemViewModel { CollectionId = collection.Id, UserName = collection.UserName, ItemName = null, Likes = 0, }; return(View(model)); } } } return(NotFound()); }
// Método para agregar un item en una orden public async Task AddItemToOrderAsync(AddItemViewModel model, string userName) { // Se carga la entidad User mediante el método que valida y trae el usuario que se a logueado var user = await this.userHelper.GetUserByEmailAsync(userName); if (user == null) { return; } // Buscamos el ProductId en la entidad Products var product = await this.context.Products.FindAsync(model.ProductId); if (product == null) { return; } // Buscamos si ya existe el producto en la orden temporal del usuario var orderDetailTemp = await this.context.OrderDetailTemps .Where(odt => odt.User == user && odt.Product == product) .FirstOrDefaultAsync(); if (orderDetailTemp == null) { // Si no existe se crea un nuevo objeto OrderDetailTemp orderDetailTemp = new OrderDetailTemp { Price = product.Price, Product = product, Quantity = model.Quantity, User = user, }; // Se adiciona el item al contexto this.context.OrderDetailTemps.Add(orderDetailTemp); } else { // Si existe se adiciona la cantidad al item orderDetailTemp.Quantity += model.Quantity; // Se actualiza el cambio en el contexto this.context.OrderDetailTemps.Update(orderDetailTemp); } // Guardo los cambios del contexto a la base de datos await this.context.SaveChangesAsync(); }
public async Task <IActionResult> AddItem([Bind("Quantity,TypeId,SalesOrderId")] AddItemViewModel addItemView) { if (ModelState.IsValid) { ShoppingList shoppingList = new ShoppingList() { Quantity = addItemView.Quantity, TypeID = addItemView.TypeId }; await salesOrderRepository.AddItemAsync(shoppingList, addItemView.SalesOrderId); return(RedirectToAction(nameof(Details), new { id = addItemView.SalesOrderId })); } return(View(addItemView)); }
//To Edit Item (Using Edit Button) public ActionResult EditItemInView(int id) { AddItemViewModel addItemModel = new AddItemViewModel { Item = _context.Items.Include("Category").SingleOrDefault(m => m.Id == id), Categories = _context.Categories.ToList() }; if (addItemModel.Item == null) { return(View("ProductSearchEnded")); } return(View(addItemModel)); }
public async Task <IActionResult> AddProduct(AddItemViewModel model, string productId) { if (!string.IsNullOrEmpty(productId)) { model.ProductId = Convert.ToInt32(productId); } if (ModelState.IsValid) { await _orderRepository.AddItemToOrderAsync(model, User.Identity.Name, User.IsInRole("ReSeller")); return(RedirectToAction("Create")); } return(View(model)); }
public async Task <IActionResult> Edit(int id, AddItemViewModel model) { if (id != model.Id) { return(NotFound()); } if (ModelState.IsValid) { UserEntity user = await _userHelper.GetUserAsync(User.Identity.Name); ItemEntity item = new ItemEntity { Id = model.Id, Name = model.Name, Price = model.Precio, PhotoUrl = model.PicturePath, Brand = _context.Brands.Find(model.MarcaId), ItemType = _context.ItemTypes.Find(model.ItemTypeId), Stock = model.Inventario, User = user }; try { if (model.PictureFile != null) { model.PicturePath = await _imageHelper.UploadImageAsync(model.PictureFile, "Items", model.PictureName); } _context.Update(item); int success = await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ItemEntityExists(item.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(model)); }
public async Task <IActionResult> Edit(Guid itemId) { Item target = await _repository.GetItemById(itemId); AddItemViewModel model = new AddItemViewModel() { Id = target.Id, Name = target.Name, Price = target.Price, Description = target.Description, Sizes = target.Sizes, Picture = target.Picture, CategoryId = target.CategoryId }; return(View(model)); }