public ActionResult Create(ItemCreate model) { ViewBag.StoreId = _id; if (IsAdmin()) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateService(); if (service == null) { return(RedirectToAction("Login", "Account")); } if (service.CreateItem(model)) { TempData["SaveResult"] = "Your Item was created."; return(RedirectToAction("Index", new { id = model.StoreId })); } ; return(View(model)); } return(RedirectToAction("Index", new { id = model.StoreId })); }
public bool CreateItem(ItemCreate model) { var entity = new Item() { //ItemId = model.ItemId, SubCatId = model.SubCatId, ItemName = model.ItemName, AisleNumber = model.AisleNumber, MaxAllowed = model.MaxAllowed, PointCost = model.PointCost, CreateBy = _userId, CreateAt = DateTimeOffset.Now }; using (var ctx = new ApplicationDbContext()) { ctx.Items.Add(entity); bool success = true; try { ctx.SaveChanges(); } catch { success = false; } return(success); } }
public async Task <IHttpActionResult> CreateAsync([FromBody] ItemCreate itemCreate) { #region //TODO Criar um BaseController para obter o usuário do token; //var context = HttpContext.Current.Request.GetOwinContext(); //var User = context.Authentication.User; //var claims = User.Claims; //var claim = claims.FirstOrDefault(x => x.Type == "UserId"); //var userValue = claim.Value.ToInt32(); //var user = 1; #endregion var user = 1; var validationResults = new ItemCreateValidator().Validate(itemCreate); if (!validationResults.IsValid) { return(this.BadRequest(string.Join(" , ", validationResults.Errors))); } var itemEntity = itemCreate.ToEntity(); var createdItem = await Task.Run(() => _appService.Create(itemEntity, user)); var itemRead = TypeAdapter.Adapt <ItemEntity, ItemRead>(createdItem); return(this.Ok(itemRead)); }
public bool SaveItem(ItemCreate newItem) { bool success; var savedItem = db.GetItem <ItemView>(newItem.ProductID, newItem.StoreID); try { if (savedItem == null) { var item = newItem.Adapt <tbl_Items>(); item.CreatedDate = DateTime.Now; item.LastUpdated = DateTime.Now; db.SaveItem(item); success = true; } else { var item = savedItem.Adapt <tbl_Items>(); item.ItemName = newItem.ItemName; item.Quantity += newItem.Quantity; item.Notes = newItem.Notes; item.LastUpdated = DateTime.Now; db.SaveItem(item); success = true; } } catch (Exception e) { throw e; } return(success); }
public async Task <ActionResult <Item> > PostItem(ItemCreate itemCreateDTO) { itemCreateDTO.UserId = User.UserGuidId(); var item = _itemMapper.ItemCreate(itemCreateDTO); _bll.ItemService.Add(item); await _bll.SaveChangesAsync(); return(CreatedAtAction("GetItem", new { id = item.Id }, item)); }
void Start() { playerHealth = GameObject.Find("HealthBar").GetComponent <Slider>(); bossHealth = GameObject.Find("BossHealthBar").GetComponent <Slider>(); pHp = playerHealth.value; bHp = bossHealth.value; characterStatus = GameObject.FindGameObjectWithTag("Player").GetComponent <CharacterStatus>(); playerDamage = characterStatus.getDamage(); itemCreate = GameObject.Find("ItemCreateMgr").GetComponent <ItemCreate>(); }
private void addButton_Click(object sender, EventArgs e) { ItemCreate item = new ItemCreate() { StoreId = AdminForm.storeId, Name = itemNameTextBox.Text, Price = float.Parse(itemPriceTextBox.Text) }; AddItem(item); }
public bool CreateItem(ItemCreate model) { var entity = new Item { Name = model.Name, Description = model.Description, LocationID = model.LocationID }; ctx.Items.Add(entity); return(ctx.SaveChanges() == 1); }
public IHttpActionResult Post(ItemCreate item) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateItemService(); if (!service.CreateItem(item)) { return(InternalServerError()); } return(Ok()); }
private async void AddItem(ItemCreate item) { string url = "http://localhost:57620/api/mycity/admin/item"; var serializedItem = JsonConvert.SerializeObject(item); var content = new StringContent(serializedItem, Encoding.UTF8, "application/json"); var result = await client.PostAsync(url, content); if (result.StatusCode == System.Net.HttpStatusCode.Created) { messageLabel.Text = "Store added successfully."; } GetItemsByStore(AdminForm.storeId); }
public ActionResult Create(int id) { ViewBag.StoreId = _id; if (IsAdmin()) { var model = new ItemCreate { StoreId = id }; return(View(model)); } return(RedirectToAction("Index", new { id })); }
public IActionResult AddItemForm(ItemStoreSelect selected) { var model = new ItemCreate(); var store = WarehouseService.GetStore(selected.StoreID); var item = ProductService.GetItem(selected.ProductID, selected.StoreID); var product = ProductService.GetProduct(selected.ProductID); model.ProductID = item == null ? product.ProductID : item.ProductID; model.ItemName = item == null ? product.ProductName : item.ItemName; model.CurrentQuantity = item == null ? 0 : item.Quantity; model.Notes = item == null ? string.Empty : item.Notes; model.StoreID = store.StoreID; model.StoreName = store.StoreName; return(PartialView("AddItemForm", model)); }
public async Task <IHttpActionResult> UpdateAsync([FromBody] ItemCreate itemCreate, [FromUri] int id) { //It does not allow activate item by this method var userId = 1; //var itemEntity = TypeAdapter.Adapt<ItemCreate, ItemEntity>(item); var itemEntity = itemCreate.ToEntity(); itemEntity.Id = id; var updItem = await Task.Run(() => _appService.Update(itemEntity, userId)); var readItems = TypeAdapter.Adapt <ItemEntity, ItemRead>(updItem); return(this.Ok(readItems)); }
public bool CreateItem(ItemCreate model) { var entity = new Item() { OwnerId = _userId, ItemName = model.ItemName, ItemDescription = model.ItemDescription, ItemType = model.ItemType, }; using (var ctx = new ApplicationDbContext()) { ctx.Items.Add(entity); return(ctx.SaveChanges() == 1); } }
public void AddItem_NonExisting_CreatedResponseWithCorrectCodeReturned() { // Arrange var customerId = "customer_1"; var itemToCreate = new ItemCreate { Name = "Item 1" + DateTime.Now.Ticks, Quantity = 5 }; // Act var response = CheckoutClient.ShoppingListService.AddItem(customerId, itemToCreate); // Assert response.Should().NotBeNull(); response.HttpStatusCode.Should().Be(HttpStatusCode.Created); response.Headers.Location.PathAndQuery.Should().BeEquivalentTo(new Uri(string.Format(ApiUrls.ShoppingListItem, customerId, itemToCreate.Name)).PathAndQuery); response.Model.Code.Should().Be(3000); }
public bool CreateItem(ItemCreate model) { var entity = new Item() { OwnerId = _userId, Name = model.Name, Nombre = model.Nombre, Location = model.Location }; using (var ctx = new ApplicationDbContext()) { ctx.Items.Add(entity); return(ctx.SaveChanges() == 1); } }
//public ActionResult WeaponCreate() //{ // return PartialView("_WeaponCreate"); //} //public ActionResult ArmorCreate() //{ // return PartialView("_ArmorCreate"); //} //public ActionResult ItemCreate() //{ // return PartialView("_ItemCreate"); //} private ActionResult Create(ItemCreate item) { if (!ModelState.IsValid) { return(View(item)); } var service = new ItemService(Guid.Parse(User.Identity.GetUserId())); if (service.CreateItem(item)) { return(RedirectToAction("Index", "Item")); } else { return(View(item)); } }
public ActionResult Create(ItemCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = new ItemService(); if (service.CreateItem(model)) { return(RedirectToAction("Index")); } ModelState.AddModelError("", "Item could not be created"); return(View(model)); }
//Create an instance of Item public bool CreateItem(ItemCreate item) { var entity = new Item() { OwnerId = _userId, //We want the user who creates the note to be the user who is logged in ItemName = item.ItemName, ItemDescription = item.ItemDescription, ItemPrice = item.ItemPrice, ItemCondition = item.ItemCondition, //CategoryName = item.CategoryName }; using (var ctx = new ApplicationDbContext()) // Access database { ctx.Items.Add(entity); // access items Table and add items return(ctx.SaveChanges() == 1); } }
public bool CreateItem(ItemCreate model) { var entity = new Item() { Name = model.Name, CategoryID = model.CategoryID, Description = model.Description, Price = model.Price, Inventory = model.Inventory, CreatedUtc = DateTime.Now }; using (var ctx = new ApplicationDbContext()) { ctx.Items.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(ItemCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = ItemServices(); if (service.CreateEquipment(model)) { TempData["SaveResult"] = "The equipment was created."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "The equipment could not be created."); return(View(model)); }
public bool CreateItem(ItemCreate model) { var entity = new Item() { ItemId = model.ItemId, StoreId = model.StoreId, ItemName = model.ItemName, Description = model.Description, Price = model.Price, OwnerId = _userId }; using (var ctx = new ApplicationDbContext()) { ctx.Items.Add(entity); return(ctx.SaveChanges() == 1); } }
public void AddItem_Existing_OkResponseWithQuantityUpdatedCodeReturned() { // Arrange var customerId = "customer_1"; var itemToCreate = new ItemCreate { Name = "Item 1" + DateTime.Now.Ticks, Quantity = 5 }; CheckoutClient.ShoppingListService.AddItem(customerId, itemToCreate); // Act var response = CheckoutClient.ShoppingListService.AddItem(customerId, itemToCreate); // Assert response.Should().NotBeNull(); response.HttpStatusCode.Should().Be(HttpStatusCode.OK); response.Model.Code.Should().Be(3002); }
public string CreateItem(ItemCreate model) { var entity = new Item() { AddedBy = _userId, Type = model.Type, Name = model.Name, Description = model.Description, CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now }; using (var ctx = new ApplicationDbContext()) { ctx.Items.Add(entity); return(ctx.SaveChanges() == 1 ? "Item Created Successfully" : "Something Went Wrong"); } }
public ActionResult Create(ItemCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateItemService(); if (service.CreateItem(model)) { TempData["SaveResult"] = "Your Item was created."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Item could not be created."); return(View(model)); }
public async Task <ActionResult> Create(ItemCreate model) { if (ModelState.IsValid == false) { return(View(model)); } var itemService = CreateItemService(); if (await itemService.CreateItem(model)) { TempData["SaveResult"] = "Your item was created."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Item could not be created"); return(View(model)); }
public IHttpActionResult Post(ItemCreate item) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (ModelState == null) { return(BadRequest("Model must not be null")); } var service = CreateItemService(); if (service.CreateItem(item) == "Something Went Wrong") { return(InternalServerError()); } return(Ok(item)); }
[ValidateAntiForgeryToken] //The basic purpose of ValidateAntiForgeryToken attribute is to prevent cross-site request forgery attacks public ActionResult Create(ItemCreate model) //[HttpPost] method will push the data inputted in the view through our service and into the db. { if (!ModelState.IsValid) { return(View(model)); //makes sure the model is valid } var service = CreateItemService(); if (service.CreateItem(model)) { //TempData removes information after it's accessed TempData["SaveResult"] = "Your note was created."; return(RedirectToAction("Index")); //returns the user back to the index view } ; ModelState.AddModelError("", "Note could not be created.");//? return(View(model)); }
public async Task <bool> CreateItem(ItemCreate model) { var entity = new Item() { OwnerId = _userId, Name = model.Name, Description = model.Description, ModelNumber = model.ModelNumber, SerialNumber = model.SerialNumber, Value = model.Value, ItemImageId = model.ItemImageId }; using (var ctx = new ApplicationDbContext()) { ctx.Items.Add(entity); return(await ctx.SaveChangesAsync() == 1); } }
public void GetItem_Existing_OkResponseWithCorrectItemReturned() { // Arrange var customerId = "customer_1"; var itemName = "Item 1" + DateTime.Now.Ticks; var quantity = 5; var itemToCreate = new ItemCreate { Name = itemName, Quantity = quantity }; CheckoutClient.ShoppingListService.AddItem(customerId, itemToCreate); // Act var response = CheckoutClient.ShoppingListService.GetItem(customerId, itemName); // Assert response.Should().NotBeNull(); response.HttpStatusCode.Should().Be(HttpStatusCode.OK); response.Model.Name.Should().Be(itemName); response.Model.Quantity.Should().Be(quantity); }
// Use this for initialization void Start() { sc = GetComponent<ItemCreate>(); sc.canOpen = true; }
// Use this for initialization void Start() { sc = GetComponent<ItemCreate>(); roomNum = Convert.ToInt16 (name); }
public async Task<ItemCreate.response> ItemCreate(ItemCreate.request request, CancellationToken? token = null) { return await SendAsync<ItemCreate.response>(request.ToXmlString(), token.GetValueOrDefault(CancellationToken.None)); }