public bool AddItem(ItemInputModel item) { Item itemDto = mapper.Map <Item>(item); bool result = itemRepository.AddItem(itemDto); return(result); }
public async Task <IActionResult> Add([FromBody] ItemInputModel item) { var isSuccessful = await this.autopartConditionService.Add(this.htmlSanitizer.Sanitize(item.Name)); if (isSuccessful) { return(this.Ok()); } return(this.BadRequest()); }
public IActionResult EditCheckListItem([FromBody] ItemInputModel item) { try { _checkListRepo.UpdateCheckListItem(item.Id, item.Text, item.Done); return(StatusCode(200, Ok())); } catch (Exception e) { return(StatusCode(400, e.Message)); } }
public async Task <ActionResult> AddItem(ItemInputModel model) { if (model != null) { var item = new Item(); item.Name = model.Name; item.Storage = model.Storage; await _itemRepository.SaveItemAsync(item); } return(Redirect("/Storage")); }
public void AddItem_WhenCalled_ReturnsTrue() { // Arrange itemRepository.Setup(s => s.AddItem(It.IsAny <Item>())).Returns(true); ItemInputModel item = new ItemInputModel { DisplayName = "Jacket", Value = 300, CategoryId = 2 }; // Act var result = itemController.AddItem(item); // Assert Assert.True(result); }
private void ItemNullCheck(IItem item, ItemInputModel input) { if (!string.IsNullOrWhiteSpace(input.Name)) { item.Name = input.Name; } if (!string.IsNullOrWhiteSpace(input.ImagePath)) { item.ImagePath = input.ImagePath; } if (item.BuyPrice > 0) { item.BuyPrice = input.BuyPrice; } if (item.SellPrice > 0) { item.SellPrice = input.SellPrice; } }
public async Task InsertItemAsync(string inputModelJson) { ItemInputModel inputModel = JsonConvert.DeserializeObject <ItemInputModel>(inputModelJson); string currentDate = DateTime.Now.ToString("dd.MM.yyyy"); long categoryId = inputModel.CategoryId; string name = inputModel.Name; string insertStatement = $"insert into item(is_del, created_on, category_id, name)values(0,'{currentDate}', {categoryId}, '{name}')"; await CommandExecuter.ExecuteNonQuaryAsync(insertStatement); double price = inputModel.Price; CenaInputModel cenaInputModel = new CenaInputModel { Cena = price, }; string cenaInputModelJson = JsonConvert.SerializeObject(cenaInputModel); await cenaService.InsertCenaAsync(cenaInputModelJson); }
public async Task Create(ItemInputModel input) { if (input.Slot == "Weapon") { this.Context.Weapons.Add(new Weapon { Name = input.Name, HealthIncrease = input.HealthIncrease, ManaIncrease = input.ManaIncrease, HealthRegenIncrease = input.HealthRegenIncrease, ManaRegenIncrease = input.ManaRegenIncrease, CritChanceIncrease = input.CritChanceIncrease, MovementSpeedIncrease = input.MovementSpeedIncrease, AttackSpeedIncrease = input.AttackSpeedIncrease, Damage = input.Damage, AttackSpeed = input.AttackSpeed, BuyPrice = input.BuyPrice, SellPrice = input.SellPrice, }); } else if (input.Slot == "Amulet") { this.Context.Amulets.Add(new Amulet { Name = input.Name, HealthIncrease = input.HealthIncrease, ManaIncrease = input.ManaIncrease, HealthRegenIncrease = input.HealthRegenIncrease, ManaRegenIncrease = input.ManaRegenIncrease, CritChanceIncrease = input.CritChanceIncrease, MovementSpeedIncrease = input.MovementSpeedIncrease, AttackSpeedIncrease = input.AttackSpeedIncrease, BuffStatType = input.StatRegenType, BuffAmount = input.RegenAmount, BuffDuration = input.BuffDuration, Cooldown = input.Cooldown, BuyPrice = input.BuyPrice, SellPrice = input.SellPrice, }); } else if (input.Slot == "Consumeable") { this.Context.Consumeables.Add(new Consumeable { Name = input.Name, Charges = input.Charges, StatRegenType = input.StatRegenType, RegenAmount = input.RegenAmount, BuyPrice = input.BuyPrice, SellPrice = input.SellPrice, }); } else { this.Context.Armors.Add(new Armor { Name = input.Name, HealthIncrease = input.HealthIncrease, ManaIncrease = input.ManaIncrease, HealthRegenIncrease = input.HealthRegenIncrease, ManaRegenIncrease = input.ManaRegenIncrease, CritChanceIncrease = input.CritChanceIncrease, MovementSpeedIncrease = input.MovementSpeedIncrease, AttackSpeedIncrease = input.AttackSpeedIncrease, ArmorValue = input.ArmorValue, ResistanceValue = input.ResistanceValue, BuyPrice = input.BuyPrice, SellPrice = input.SellPrice, Slot = input.Slot, }); } await this.SaveAsync(); }
public async Task Update(string type, int id, ItemInputModel input) { if (type == "Amulet") { var amulet = await this.Context.Amulets.FindAsync(id); if (!string.IsNullOrWhiteSpace(input.BuffStatType)) { amulet.BuffStatType = input.BuffStatType; } if (input.BuffDuration > 0) { amulet.BuffDuration = input.BuffDuration; } if (input.Cooldown > 0) { amulet.Cooldown = input.Cooldown; } this.ItemNullCheck(amulet, input); this.EquipableItemNullCheck(amulet, input); } else if (type == "Armor") { var armor = await this.Context.Armors.FindAsync(id); if (input.ArmorValue > 0) { armor.ArmorValue = input.ArmorValue; } if (input.ResistanceValue > 0) { armor.ResistanceValue = input.ResistanceValue; } this.ItemNullCheck(armor, input); this.EquipableItemNullCheck(armor, input); } else if (type == "Weapon") { var weapon = await this.Context.Weapons.FindAsync(id); if (input.AttackSpeed > 0) { weapon.AttackSpeed = input.AttackSpeed; } if (input.Damage > 0) { weapon.Damage = input.Damage; } this.ItemNullCheck(weapon, input); this.EquipableItemNullCheck(weapon, input); } else { var consumeable = await this.Context.Consumeables.FindAsync(id); if (!string.IsNullOrWhiteSpace(input.StatRegenType)) { consumeable.StatRegenType = input.StatRegenType; } if (input.RegenAmount > 0) { consumeable.RegenAmount = input.RegenAmount; } this.ItemNullCheck(consumeable, input); } await this.SaveAsync(); }
private async void btnAdd_Click(object sender, EventArgs e) { string itemName = textName.Text; if (string.IsNullOrEmpty(itemName)) { MessageBox.Show("Insert item name"); return; } if (itemName.Length > 100) { MessageBox.Show("Item name must be between 0 and 100 symbols"); return; } if (comboCategory.SelectedIndex == -1) { MessageBox.Show("Item must have category!"); return; } string priceString = textPrice.Text; if (string.IsNullOrEmpty(priceString)) { MessageBox.Show("Item must have price!"); return; } double price = -1d; if (!double.TryParse(DecimalPointConverter.GetStringDecimal(priceString), out double result)) { MessageBox.Show("Price must be a number!"); return; } price = result; long categoryId = long.Parse(comboCategory.SelectedValue.ToString()); ItemInputModel inputModel = new ItemInputModel { CategoryId = categoryId, Name = itemName, Price = price, }; string inputModelJson = JsonConvert.SerializeObject(inputModel); await itemService.InsertItemAsync(inputModelJson); MessageBox.Show("Successfully insert artikul"); var dialogResult = MessageBox.Show("Will you insert more artikuls?", "IncomeManager", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.No) { Close(); } textName.ResetText(); textPrice.ResetText(); }