Example #1
0
        public ActionResult AddNewItem(UItem model, Guid orId, bool editMode)
        {
            //maintain session OR variable if not null
            if (UserSession.CurrentSession.NewOR != null)
            {
                var or = UserSession.CurrentSession.NewOR;
            }
            Item item = itemService.GetItemByName(model.Name, countryProg.Id);

            if (item == null)
            {
                item                      = new Item();
                item.Name                 = model.Name;
                item.ItemCategoryId       = model.ItemCategoryId;
                item.ItemClassificationId = model.ItemClassificationId;
                item.UnitOfMessureId      = model.UnitId;
                item.CountryProgrammeId   = countryProg.Id;
                item.IsApproved           = false;
                itemService.AddItem(item);
            }
            if (editMode)
            {
                return(AddItemInEditMode(orId));
            }
            return(PopulateCreateItem(orId, "", item.Id));
        }
Example #2
0
 public void Add(Item item)
 {
     try
     {
         if (item != null)
         {
             _itemService.AddItem(new Item {
                 Id          = item.Id,
                 Name        = item.Name,
                 Description = item.Description,
                 Price       = item.Price, Available =
                     item.Available,
                 Size = item.Size
             }
                                  );
             _logger.LogInformation($"Item {item.Name} added.");
         }
     }
     catch (Exception ex)
     {
         _logger.LogError("An error was caught while adding a new item.");
         _logger.LogError($"Error: {ex.Message}");
         throw;
     }
 }
Example #3
0
 public ActionResult CreateEdit(UItem item, string Action = "")
 {
     if (ModelState.IsValid)
     {
         if (Action.Equals("Edit"))
         {
             item._item.CountryProgrammeId = countryProg.Id;
             if (itemService.EditItem(item._item))
             {
                 ModelState.Clear();
                 item = new UItem();
             }
         }
         else
         {
             item._item.CountryProgrammeId = countryProg.Id;
             if (itemService.AddItem(item._item))
             {
                 ModelState.Clear();
                 item = new UItem();
             }
         }
     }
     return(RedirectToAction("ListView"));
 }
 public IActionResult Create([FromForm] ItemVM itemVM)
 {
     try
     {
         if (itemVM.Image.Length <= 0)
         {
             return(BadRequest("Image is null"));
         }
         var item = new Item
         {
             BrandCategoryID     = itemVM.BrandCategoryID,
             GenderSubCategoryID = itemVM.GenderSubCategoryID,
             Description         = itemVM.Description,
             Price = itemVM.Price,
             Name  = itemVM.Name
         };
         var newItem      = _itemService.AddItem(item);
         var newItemImage = _itemImageService.Add(itemVM.Image, newItem.ID);
         return(CreatedAtRoute("GetItemById", new { id = newItem.ID }, newItem));
     }
     catch (Exception ex)
     {
         return(BadRequest("Item is null"));
     }
 }
Example #5
0
        public IActionResult AddItem(Item item)
        {
            try
            {
                itemService.CheckItem(item);
            }
            catch (ErrorDataException)
            {
                itemsAndCategories.AllCategories = itemService.ShowCategories();

                return(View(itemsAndCategories));
            }
            try
            {
                itemService.AddItem(item);
            }
            catch (ErrorDataException)
            {
                itemsAndCategories.AllCategories = itemService.ShowCategories();
                ModelState.AddModelError("Item", "Този продукт вече съществува!");

                return(View(itemsAndCategories));
            }

            itemsAndCategories.AllCategories = itemService.ShowCategories();
            return(RedirectToAction("Index", "Home"));
        }
        public async Task <ActionResult <Item> > Create(EditItemViewModel itemModel, int storeId)
        {
            try
            {
                var item = new Item
                {
                    Name          = itemModel.Name,
                    Ingredients   = itemModel.Ingredients,
                    ItemImageUrl  = itemModel.ItemImageUrl,
                    Price         = itemModel.Price,
                    StoreId       = storeId,
                    ItemModifiers = itemModel.ItemModifiers
                                    .Where(modifier => modifier.Selected)
                                    .Select(modifier => new ItemModifier
                    {
                        ModifierId     = modifier.Id,
                        AdditionalCost = modifier.AdditionalCost ?? 0
                    })
                                    .ToList()
                };
                await itemService.AddItem(item, storeId);

                return(RedirectToAction(nameof(Index), new { storeId }));
            }
            catch
            {
                return(View(itemModel));
            }
        }
Example #7
0
        //public HttpResponseMessage CreateItem(string Name, double Price, string Description, bool IsReserved, int NumberOfItems, DateTime Date)
        public HttpResponseMessage CreateItem([FromBody] ItemViewModel model)
        {
            if (ModelState.IsValid)
            {
                // create new item
                var item = new Item()
                {
                    Name          = model.Name,
                    Price         = model.Price,
                    Description   = model.Description,
                    IsReserved    = model.IsReserved,
                    NumberOfItems = model.NumberOfItems,
                    Date          = DateTime.Now
                };

                // add item in db
                _itemService.AddItem(item);

                // return response
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, item);
                response.Headers.Location = new Uri(Url.Link("ReservedItems", new { id = item.Id }));
                return(response);
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
Example #8
0
        public async Task <IActionResult> AddItem(Item Item)
        {
            var item = await _ItemService.AddItem(Item);

            var Iteme = _mapper.Map <ItemDTO>(item);

            return(Ok(Iteme));
        }
Example #9
0
        public void SaveItem([FromBody] dynamic item)
        {
            var request = new ServiceRequest
            {
                Request = item
            };

            _itemService.AddItem(request);
        }
Example #10
0
 public IActionResult Create([FromBody] EditItemVM model)
 {
     if (ModelState.IsValid)
     {
         string user      = User.Identity.Name;
         int    newItemId = _itemService.AddItem(model, user);
         return(CreatedAtAction(nameof(GetDetails), new { id = newItemId }, model));
     }
     return(BadRequest());
 }
Example #11
0
        /*
         * POST
         * api/item
         */
        public IActionResult Create([FromBody] Item item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            _service.AddItem(item);

            return(CreatedAtRoute("GetItem", new { id = item.ItemId }, item));
        }
Example #12
0
        public async Task <IHttpActionResult> AddItem(ItemViewModel item)
        {
            item.IsDisabled = false;
            var addedItem = await _itemService.AddItem(item);

            if (addedItem == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            return(Ok(addedItem));
        }
 public IHttpActionResult addItem(ItemDTO item)
 {
     if (!string.IsNullOrWhiteSpace(item.Codi) && item.Preu > 0)
     {
         return(Ok(_is.AddItem(item)));
     }
     else
     {
         return(BadRequest("Item is not valid"));
     }
 }
Example #14
0
        public ActionResult AddItem(AddItemDto model)
        {
            if (ModelState.IsValid)
            {
                var itemId = _itemService.AddItem(model);

                return(RedirectToAction("ItemDetails", "Item", _itemService.ItemDetails(itemId)));
            }
            model.Categories = _categoryService.GetCategoryList();
            return(View(model));
        }
        public IHttpActionResult Post(int theaterId, Item item)
        {
            var newItem = _itemService.AddItem(theaterId, item);

            if (newItem == null)
            {
                return(BadRequest());
            }

            return(Ok(newItem));
        }
Example #16
0
        public IActionResult Add([FromBody] Item item)
        {
            Item addedItem = _itemService.AddItem(item);

            return(addedItem != null ? new ObjectResult(addedItem)
            {
                StatusCode = StatusCodes.Status201Created
            } : new ObjectResult(addedItem)
            {
                StatusCode = StatusCodes.Status400BadRequest
            });
        }
Example #17
0
 private void SaveItem()
 {
     try
     {
         var item = new Item(txtName.Text, numCount.Value, int.Parse(cmbCountType.SelectedValue.ToString()));
         _itemService.AddItem(item);
         _unitOfWork.SaveChanges();
     }
     catch (Exception e)
     {
         MessageBox.Show("عملیات با مشکل مواجه شد");
     }
 }
Example #18
0
        public async Task <IActionResult> Post([FromBody] ItemDTO value)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid model"));
                }
                await _service.AddItem(value);

                return(StatusCode(201));
            }
            catch
            {
                return(StatusCode(400));
            }
        }
        private void OnSave_Click(object sender, RoutedEventArgs e)
        {
            Item item = new Item()
            {
                Id          = Int32.Parse(this.TxtId.Text),
                Name        = this.TxtName.Text,
                Description = this.TxtDescription.Text,
                Price       = Decimal.Parse(this.TxtPrice.Text)
            };

            itemservice.AddItem(item);
            MessageBox.Show("Successfully Edit Item!");
            ViewItem viewItem = new ViewItem(); //create your new form.

            viewItem.Show();                    //show the new form.
            this.Close();
        }
Example #20
0
        public IActionResult EditItem(EditItemVM model)
        {
            int newItemId = 0;

            if (ModelState.IsValid)
            {
                if (model.Id == 0)
                {
                    newItemId = _itemService.AddItem(model, User.Identity.Name);
                }
                else
                {
                    newItemId = _itemService.EditItem(model, User.Identity.Name);
                }
                return(RedirectToAction("ItemDetails", new { id = newItemId }));
            }
            return(View(model));
        }
        public long AddLineItem(ItemBindingModel model, long expectedReceiptLineId)
        {
            Expression <Func <Product, bool> > res = x => x.ProductCode.ToLower() == model.ProductCode.ToLower();
            var product   = _productService.GetByProductCode(model.ProductCode);
            var brand     = _brandService.GetByBrandCode(model.BrandCode);
            var warehouse = _warehouseService.GetByWarehouseCode(model.WarehouseCode);
            var location  = _locationService.GetByLocationCode(model.LocationCode);
            var item      = new Item
            {
                ProductId    = product?.Id ?? null,
                ItemCode     = model.ItemCode,
                Description  = model.Description,
                CustomerId   = model.CustomerId,
                WarehouseId  = warehouse?.Id ?? null,
                LocationId   = location?.Id ?? null,
                BrandId      = model?.BrandId ?? brand?.Id ?? null,
                ReceivedBy   = model.ReceivedBy,
                ReceivedDate = model.ReceivedDate,
                ExpiryDate   = model.ExpiryDate,
            };


            long retId  = _itemService.AddItem(item);
            long itemId = 0;

            if (retId == 0)
            {
                itemId = _itemService.GetByItemCode(item.ItemCode, item.CustomerId).Id;
            }

            var expectedReceiptLine = _ExpectedReceiptLineRepository.GetById(expectedReceiptLineId);

            expectedReceiptLine.BrandId         = model?.BrandId ?? brand?.Id ?? null;
            expectedReceiptLine.ProductId       = product?.Id ?? null;
            expectedReceiptLine.UomId           = model?.UomId ?? null;
            expectedReceiptLine.Quantity        = model.Quantity;
            expectedReceiptLine.ItemCode        = model.ItemCode;
            expectedReceiptLine.ItemDescription = model.Description;
            expectedReceiptLine.ItemId          = retId == 0 ? itemId : retId;
            expectedReceiptLine.IsItemExist     = true;
            expectedReceiptLine.StatusId        = 32;
            _ExpectedReceiptLineRepository.Update(expectedReceiptLine);
            return(expectedReceiptLine.Id);
        }
        public async Task <IActionResult> AddItem(ItemModel model)
        {
            if (ModelState.IsValid)
            {
                string directory = "Images";
                string fileName  = await _saveFileService.SaveFile(model.image, Path.Combine(_env.WebRootPath, directory));

                Item item = new Item()
                {
                    description = model.description,
                    price       = model.price,
                    title       = model.title,
                    imagePath   = Path.Combine(directory, fileName),
                    CategoryId  = model.categoryId
                };
                await _itemService.AddItem(item);
            }
            return(RedirectToAction("GetItemsPage"));
        }
Example #23
0
        public IHttpActionResult AddItem(string name, int count, int countType)
        {
            var result = new BaseResult();

            try
            {
                var item = new Item(name, count, countType);
                _itemService.AddItem(item);

                result.ResultCode = Results.Success.GetCode();
                result.Message    = Results.Success.GetDescription();
                _unitOfWork.SaveChanges();
            }
            catch (Exception e)
            {
                result.ResultCode = Results.Exception.GetCode();
                result.Message    = Results.Exception.GetDescription();
            }
            return(Ok(result));
        }
        public async Task <IActionResult> AddItem(string jsonString, IFormFile image)
        {
            Result <Item> returnModel = new Result <Item>();
            Item          item        = null;

            try
            {
                item = JsonConvert.DeserializeObject <Item>(jsonString);

                returnModel = await _itemService.AddItem(item, image);
            }
            catch (Exception ex)
            {
                returnModel.isSuccess    = false;
                returnModel.ErrorMessage = ex.Message;
                returnModel.ErrorDetail  = ex.GetBaseException().Message;
            }

            return(Ok(returnModel));
        }
Example #25
0
        public bool AddOrder(OrderView newOrder)
        {
            if (newOrder.customerId < 1)
            {
                return(false);
            }

            var order = Order.Factory.Create(newOrder.Description);

            int newOrderId = _repo.CreateOrder(order, newOrder.customerId);

            if (newOrderId > 0)
            {
                foreach (ItemView iv in newOrder.Items)
                {
                    var item = Item.Factory.Create(newOrderId, iv.Amount, iv.Price);
                    _itemServ.AddItem(item);
                }
            }
            return(newOrderId > 0);
        }
Example #26
0
        public ActionResult AddNewItem(UItem model, Guid ppId, bool editMode)
        {
            Item item = itemService.GetItemByName(model.Name, countryProg.Id);

            if (item == null)
            {
                item                      = new Item();
                item.Name                 = model.Name;
                item.ItemCategoryId       = model.ItemCategoryId;
                item.ItemClassificationId = model.ItemClassificationId;
                item.UnitOfMessureId      = model.UnitId;
                item.CountryProgrammeId   = countryProg.Id;
                item.IsApproved           = false;
                itemService.AddItem(item);
            }
            if (editMode)
            {
                return(EditPPItem(ppId));
            }
            return(CreatePPItem(ppId));
        }
Example #27
0
 public ActionResult <ItemDTOWithoutID> AddItem(ItemDTOWithoutID itemDTO)
 {
     itemService.AddItem(itemMapper.ToItem(itemDTO));
     return(Ok(itemDTO));
 }
Example #28
0
        public IActionResult NewItem([FromBody] Item item)
        {
            _itemService.AddItem(item);

            return(Ok(item));
        }
Example #29
0
        public async Task <IActionResult> AddItem([FromBody] AddItem item)
        {
            await _itemService.AddItem(item.ItemName, item.IdRoom);

            return(Accepted());
        }
Example #30
0
 public IActionResult AddItem(NewItemVm model)
 {
     _itemService.AddItem(model);
     return(RedirectToAction("ViewAllItems"));
 }