public void PurchaseCanceled() { //Return to store confirmPopUp.SetActive(false); notEnoughFunds.SetActive(false); itemInCart = null; }
public void ShowItemInfo(StoreItemModel data) { IDialog dialog = DialogManager.instance.SpawnDialogBasedOnType(GameEnum.DialogType.InfoDialog); dialog.SetTitle(data.itemType.ToString()); dialog.SetMessage(GetStoreItemDetailsBasedOnType(data.itemType)); }
public static StoreItemModel ConvertStoreItemToModel(StoreItem storeItem) { if (storeItem == null) { return(null); } List <ImageModel> storeImages = new List <ImageModel>(); List <SpecificationModel> specifications = new List <SpecificationModel>(); List <CommentModel> comments = new List <CommentModel>(); if (storeItem.Images != null) { foreach (var image in storeItem.Images) { var imageFileBase = ConvertToImageModel(image); if (imageFileBase == null) { continue; } storeImages.Add(imageFileBase); } } if (storeItem.Specification != null) { foreach (var specification in storeItem.Specification) { SpecificationModel specificationModel = ConvertToSpecificationModel(specification); specifications.Add(specificationModel); } } if (storeItem.UserComments != null) { foreach (var userComment in storeItem.UserComments) { CommentModel commentModel = CommentProcessor.ConvertToCommentModel(userComment); comments.Add(commentModel); } } StoreItemModel model = new StoreItemModel { Id = storeItem.Id, Name = storeItem.Name, Discription = storeItem.Discription, Brand = storeItem.Brand, Price = storeItem.Price, Discount = storeItem.DiscountPercentage, Images = storeImages, InStock = storeItem.InStock, Specifications = specifications, Comments = comments, }; return(model); }
public ActionResult Edit(StoreItemModel model) { var storeItem = _storeItemRepository.GetById(model.Id); if (ModelState.IsValid) { storeItem = model.ToEntity(storeItem); //always set IsNew to false when saving storeItem.IsNew = false; //update attributes _storeItemRepository.Update(storeItem); //commit all changes this._dbContext.SaveChanges(); //notification SuccessNotification(_localizationService.GetResource("Record.Saved")); return(new NullJsonResult()); } else { return(Json(new { Errors = ModelState.SerializeErrors() })); } }
public void PurchaseConfirmed() { //Confirm purchase and adjust coin amount accordigly currentCoinAmount -= itemInCart.goldPrice; coins.text = "Coins: " + currentCoinAmount.ToString(); confirmPopUp.SetActive(false); EventManager.TriggerEvent(EventTypes.PURCHASE_CONFIRMED); SaveLoadController.GetInstance().GetPlayer().AddTotalCoins(-itemInCart.goldPrice); //substract coins from player SaveLoadController.GetInstance().GetPlayer().AddUnlockedItem(itemInCart.itemID); //unlock skin for player SetSkinActive(itemInCart.itemID); // Set skin active. This also saves the game // Send event data // This is very ugly but ok for now switch (itemInCart.skinName) { case "Vladimir": GooglePlayHelper.GetInstance().ReportEvent(GPGSConstant.event_store_default_skin_bought, 1); break; default: break; } itemInCart = null; }
public StoreItem GetStoreItemById(StoreItemModel storeItem) { DBEntities entities = new DBEntities(); return((from c in entities.StoreItems where (c.Id == storeItem.Id) select c).FirstOrDefault()); }
public async Task <IActionResult> Post([FromBody] StoreItemModel model) { var item = await _service.Create(model); return(CreatedAtAction(nameof(Get), new { id = item.Id }, item)); }
private void SetupUi(StoreItemModel item) { if (item == null) { return; } _txtPrice.text = item.price + ""; _imgItem.sprite = item.itemImage; }
//retrieves all store item from repostoreitem and insert it into storeitemmodel as a list public StoreItemModel ServItems(int id) { //stores all store items from a location into the items field var items = _repoStoreItem.GetAllStoreItemByLocationId(id); StoreItemModel storeItem = new StoreItemModel { storeItems = items.ToList() }; return(storeItem); }
private void Start() { //Disable confirm purchase popup confirmPopUp.SetActive(false); notEnoughFunds.SetActive(false); itemInCart = null; //Show amount of coins from savegame coinAmountFromSave = SaveLoadController.GetInstance().GetPlayer().GetTotalCoins(); currentCoinAmount = coinAmountFromSave; coins.text = "Coins: " + currentCoinAmount.ToString(); }
public static StoreItem ConvertModelToStoreItem(StoreItemModel model) { if (model == null) { return(null); } List <StoreImage> StoreImages = new List <StoreImage>(); List <Specification> Specifications = new List <Specification>(); if (model.Images != null) { foreach (var imageData in model.Images) { StoreImage storeImage = new StoreImage { Id = imageData.Id, ImageData = imageData.Image, }; StoreImages.Add(storeImage); } } if (model.Specifications != null) { foreach (var specificationModel in model.Specifications) { Specification specification = new Specification { Id = Guid.NewGuid(), Name = specificationModel.Name, Description = specificationModel.Description }; Specifications.Add(specification); } } StoreItem storeItem = new StoreItem { Id = model.Id, Name = model.Name, Discription = model.Discription, Price = model.Price, DiscountPercentage = model.Discount, Brand = model.Brand, Images = StoreImages, InStock = model.InStock, Specification = Specifications }; return(storeItem); }
public static void UpdateStoreItem(StoreItemModel model) { UnitOfWorkRepository unitOfWork = new UnitOfWorkRepository(); StoreItem storeItem = ConvertModelToStoreItem(model); if (storeItem == null) { return; } unitOfWork.StoreItemRepository.Update(storeItem); }
private void Init(MainWindow w) { _w = w; _db = _w.Database; _pd = new ProductAttributeModel(); StackPanelAttribute.DataContext = _pd; _model = new StoreItemModel() { StoreItemType = StoreItemType.Product, AttributeProductPairs = new List <AttributeStoreItemPair>() }; DataContext = _model; DataGridPairs.ItemsSource = _model.AttributeProductPairs.ToList(); }
public static void CreateStoreItem(StoreItemModel model) { if (model == null) { return; } UnitOfWorkRepository unitOfWork = new UnitOfWorkRepository(); var storeItem = ConvertModelToStoreItem(model); unitOfWork.StoreItemRepository.Add(storeItem); }
public static StoreItemModel GetStoreItemModelbyId(Guid id) { UnitOfWorkRepository unitOfWork = new UnitOfWorkRepository(); var result = unitOfWork.StoreItemRepository.Get(id); if (result == null) { return(null); } StoreItemModel model = ConvertStoreItemToModel(result); return(model); }
public ActionResult Edit(StoreItemModel model, List <HttpPostedFileBase> StoreImages) { var checkModel = StoreItemProcessor.GetStoreItemModelbyId(model.Id); if (StoreImages != null && StoreImages[0] != null) { var imageData = StoreItemProcessor.ConverToBytes(StoreImages); var imagemodels = StoreItemProcessor.ConvertToImageModel(imageData); model.Images = imagemodels; } StoreItemProcessor.UpdateStoreItemImages(model); return(RedirectToAction("AllProducts")); }
private void PurchaseStarted(GameObject item) { //Check price and current amount StoreItemModel itemToPurchase = item.GetComponent <StoreItemModel>(); if (itemToPurchase.goldPrice <= currentCoinAmount) { itemInCart = itemToPurchase; //save item player wants to purchase (Cart) confirmPopUp.SetActive(true); } else { notEnoughFunds.SetActive(true); } }
public void TestHomeControllerItems() { //Arrange var options = new DbContextOptionsBuilder <Project1Context>() .UseInMemoryDatabase(databaseName: "Test17") .Options; StoreLocation storeLocation = new StoreLocation() { Location = "Houston" }; List <StoreItem> storeItem = new List <StoreItem>() { new StoreItem { itemName = "Chicken", itemPrice = 5, StoreLocation = storeLocation }, new StoreItem { itemName = "Pig", itemPrice = 10, StoreLocation = storeLocation } }; StoreItemModel listItems = new StoreItemModel() { storeItems = storeItem }; int locations; using (var db1 = new Project1Context(options)) { db1.AddRange(storeLocation, storeItem[0], storeItem[1]); db1.SaveChanges(); locations = db1.StoreLocations.First().StoreLocationId; } var mock = new Mock <IServiceHome>(); mock.Setup(x => x.ServItems(locations)).Returns(listItems); var controller = new HomeController(null, null, null, null, null, mock.Object); //Act var actual = controller.Items(locations); //Assert var viewResult = Assert.IsAssignableFrom <ViewResult>(actual); var list = Assert.IsAssignableFrom <StoreItemModel>(viewResult.Model); }
public void TestServItems() { //Arrange var options = new DbContextOptionsBuilder <Project1Context>() .UseInMemoryDatabase(databaseName: "Test15") .Options; StoreLocation storeLocation = new StoreLocation() { Location = "Houston" }; List <StoreItem> storeItem = new List <StoreItem>() { new StoreItem { itemName = "Chicken", itemPrice = 5 }, new StoreItem { itemName = "Pig", itemPrice = 10 } }; IEnumerable <StoreItem> items; int locationId = 1; string itemName; //Act using (var db3 = new Project1Context(options)) { storeItem[0].StoreLocation = storeLocation; storeItem[1].StoreLocation = storeLocation; db3.AddRange(storeLocation, storeItem[0], storeItem[1]); db3.SaveChanges(); //access the db for item at specific location and gets the total number of them. items = db3.StoreItems.Include(x => x.StoreLocation) .Where(x => x.StoreLocation.StoreLocationId == locationId); StoreItemModel storeItems = new StoreItemModel { storeItems = items.ToList() }; itemName = storeItem.Last().itemName; } //Assert //it should return the number of items available in the location Assert.Equal("Pig", itemName); }
public StoreItemInfoWindow(MainWindow w, StoreItem item) { InitializeComponent(); Init(w); _isEditMode = true; _model = new StoreItemModel() { StoreItemID = item.StoreItemID, Description = item.Description, AttributeProductPairs = item.AttributeProductPairs, Price = item.Price, StoreItemType = item.StoreItemType, Title = item.Title }; DataContext = _model; DataGridPairs.ItemsSource = _model.AttributeProductPairs.ToList(); }
public static void AddToShoppingCart(Guid id, StoreItemModel storeItemModel) { UnitOfWorkRepository unitOfWork = new UnitOfWorkRepository(); var StoreItem = StoreItemProcessor.ConvertModelToStoreItem(storeItemModel); var user = UserProcessor.GetUser(id); if (!(user is Customer)) { return; } var customer = (Customer)user; if (StoreItem == null) { return; } ChangeStoreItemStock(StoreItem, -1); int amount = 0; for (int i = 0; i < customer.ShoppingCart.Count(); i++) { if (customer.ShoppingCart[i].StoreItemId == storeItemModel.Id) { amount++; } } if (amount == 0) { var shoppingCart = ConvertStoreItemToShoppingCart(StoreItem); unitOfWork.CustomerRepository.AddToShoppingCart(id, shoppingCart); } else // there are multible items equal to storeItemModel { //update storeItem amount var currenthoppingCart = customer.ShoppingCart.Where(x => x.StoreItemId == storeItemModel.Id).FirstOrDefault(); int newAmount = currenthoppingCart.Amount + 1; unitOfWork.CustomerRepository.UpdateShoppingCart(id, currenthoppingCart.Id, newAmount); } }
public ActionResult AddProduct(StoreItemModel model, List <HttpPostedFileBase> StoreImages) { if (model == null || !ModelState.IsValid) { return(View()); } if (StoreImages != null) { var imageData = StoreItemProcessor.ConverToBytes(StoreImages); var imagemodels = StoreItemProcessor.ConvertToImageModel(imageData); model.Images = imagemodels; } model.Id = Guid.NewGuid(); StoreItemProcessor.CreateStoreItem(model); return(RedirectToAction("AllProducts")); }
public static List <StoreItemModel> ConvertAllStoreItemToModels() { UnitOfWorkRepository unitOfWork = new UnitOfWorkRepository(); var result = unitOfWork.StoreItemRepository.Get(); if (result == null) { return(null); } List <StoreItemModel> models = new List <StoreItemModel>(); foreach (var storeItem in result) { StoreItemModel model = ConvertStoreItemToModel(storeItem); models.Add(model); } return(models); }
public async Task <TStoreItem> AddStoreItem <TStoreItem>(string storeKey, TStoreItem item) { return(await new TaskFactory().StartNew(() => { if (string.IsNullOrWhiteSpace(storeKey)) { throw new ArgumentNullException(nameof(storeKey)); } lock (_store) { var store = _store.Where(kvp => storeKey.Equals(kvp.Value.Key)).FirstOrDefault(); var lst = new StoreItemModel[store.Value.Passwords.Length + 1]; store.Value.Passwords.CopyTo(lst, 0); lst[lst.Length - 1] = item as StoreItemModel; store.Value.Passwords = lst; _store[store.Key] = store.Value; } return item; })); }
private List <StoreItemModel> GetStoreItemListFromScriptableList(List <StoreItemScriptable> scriptableList) { List <StoreItemModel> itemList = new List <StoreItemModel>(); if (scriptableList == null) { return(itemList); } for (int i = 0; i < scriptableList.Count; i++) { StoreItemModel item = new StoreItemModel(); item.itemName = scriptableList[i].name; item.itemType = scriptableList[i].itemType; item.itemImage = scriptableList[i].itemImage; item.isPurchased = scriptableList[i].isPurchased; item.price = scriptableList[i].price; item.playerId = scriptableList[i].playerId; itemList.Add(item); } return(itemList); }
public void Setup(StoreItemModel item) { this.itemData = item; SetupUi(item); }
public ActionResult Delete(StoreItemModel model) { StoreItemProcessor.RemoveStoreItem(model); return(RedirectToAction("AllProducts")); }
public async Task <IActionResult> Put(Guid id, [FromBody] StoreItemModel model) { return(Ok(await _service.Update(id, model))); }
public void BuyButtonClicked(StoreItemModel data) { }