private void BtnAddSurveyQuestion_Tapped(object sender, TappedRoutedEventArgs e)
        {
            item             = new Item();
            this.DataContext = item;

            try
            {
                if (cboDataType.SelectedItem == null)
                {
                    Jeeves.ShowMessage("Error", "Please select a data type");
                    return;
                }
                else if (txtSurveyQuestion.Text != "")
                {
                    DataType selectedDataType = (DataType)cboDataType.SelectedItem;

                    item.ItemID    = Guid.NewGuid().ToString();
                    item.ItemName  = (string)txtSurveyQuestion.Text;
                    item.ValueType = selectedDataType.DisplayText;
                    itemRepo.AddItem(item);
                    ClearFields();
                }
            }
            catch (Exception ex)
            {
                Jeeves.ShowMessage("Error", ex.GetBaseException().Message.ToString());
            }
            FillFields();
        }
        public async Task <Order> AddItem(AppUser user, int productId)
        {
            // TODO: Заебашить проверки. И вообще, код - говно, следует переписать!
            var cart = _orderRepository.GetCartByUserId(user.Id);

            if (cart == null)
            {
                cart = _cartUseCases.CreateNewCart(user);
                _orderRepository.UpdateOrder(cart);
            }
            var product = _productRepository.GetProduct(productId);

            var cartItem = _itemRepository.GetItem(cart.Id, productId);

            if (cartItem == null)
            {
                cartItem = CreateNewItem(cart.Id, productId);
                await _itemRepository.AddItem(cartItem);
            }
            else
            {
                cartItem.ProductQuantity += 1;
                _itemRepository.UpdateItem(cartItem);
            }
            _orderRepository.Save();
            return(cart);
        }
示例#3
0
        public async Task Build()
        {
            var data = await _dtoStore.GetAllData();

            var dataSplitByLine = data.Split('\n');

            bool valuesParsed = ParseValues.ParseFromStringToInt(dataSplitByLine[0].Split()[0], out int count);

            if (!valuesParsed)
            {
                throw new Exception("Count Values is wrong");
            }
            for (int i = 1; i <= count; i++)
            {
                var properties = dataSplitByLine[i].Split();

                valuesParsed = ParseValues.ParseFromStringToInt(properties[0], out int value);
                valuesParsed = ParseValues.ParseFromStringToInt(properties[1], out int weight) && valuesParsed;

                if (valuesParsed)
                {
                    var item = new Domain.Entities.ItemEntity.Item(value, weight);
                    _itemRepository.AddItem(item);
                }
            }
        }
示例#4
0
        public async Task <JsonResult> Post([FromBody] ItemVM vm)
        {
            try
            {
                var appUser = await GetAppUser();

                Item item      = Mapper.Map <Item>(vm);
                var  addedItem = _repo.AddItem(appUser.Id, item);
                if (addedItem == null)
                {
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(Json(new { message = "Unable to add item." }));
                }
                else
                {
                    Response.StatusCode = (int)HttpStatusCode.OK;
                    return(Json(Mapper.Map <ItemVM>(addedItem)));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error while adding item: {ex}");
                Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                return(Json(new { message = "Unable to add item." }));
            }
        }
 public ActionResult CreateItem(ItemViewModel model)
 {
     if (ModelState.IsValid)
     {
         HttpPostedFileBase file = model.Item.ImageUpload;
         try
         {
             model.Item.Photo = model.Item.ImageUpload.FileName;
             file.SaveAs(Server.MapPath(@"~\ItemImage\" + file.FileName));
             model.Item.Photo = "~/ItemImage/" + file.FileName;
             if (itemRepository.AddItem(model.Item.MapFromClientToServer()))
             {
                 TempData["Message"] = "Item saved successfully.";
             }
             return(RedirectToAction("Item"));
         }
         catch
         {
             TempData["Message"] = "Something went wrong. Please Try again!";
             return(View(model));
         }
     }
     else
     {
         HttpPostedFileBase file = model.Item.ImageUpload;
         model.Item.Photo = model.Item.ImageUpload.FileName;
         file.SaveAs(Server.MapPath(@"~\ItemImage\" + file.FileName));
         model.Item.Photo = "~/ItemImage/" + file.FileName;
         return(View(model));
     }
 }
示例#6
0
        public async Task <Result <Item> > AddItem(Item model, IFormFile image)
        {
            Result <Item> returnModel  = new Result <Item>();
            string        base64String = String.Empty;

            if (model == null)
            {
                returnModel.isSuccess = false;
                return(returnModel);
            }
            if (image != null)
            {
                using (var ms = new MemoryStream())
                {
                    await image.CopyToAsync(ms);

                    var imageBytes = ms.ToArray();

                    // Convert byte[] to Base64 String
                    base64String = Convert.ToBase64String(imageBytes);
                }
                model.ImgUrl = base64String;
            }
            var domainItem = new ItemTypeAdapter().Adapt <ShopBridge.DAL.Model.Item>(model);
            var item       = await _itemRepository.AddItem(domainItem);

            returnModel.isSuccess = true;
            return(returnModel);
        }
示例#7
0
        public int AddItem(NewItemVm itemVm)
        {
            var categories = _categoryRepo.GetAllCategories();
            var item       = _mapper.Map <Item>(itemVm);
            var id         = _itemRepo.AddItem(item);

            return(id);
        }
示例#8
0
 public void Post([FromBody] ItemParams newItem)
 {
     _itemRepository.AddItem(new Item {
         Id   = newItem.Id,
         Name = newItem.Name,
         Tipo = newItem.Tipo
     });
 }
示例#9
0
        public int AddItem(EditItemVM ItemVM, string userName)
        {
            Item newItem = new Item();

            itemMapping.MapItemEntityFromVM(ItemVM, newItem);
            int itemId = _itemRepository.AddItem(newItem, userName);

            return(itemId);
        }
示例#10
0
 public IActionResult AddItem([FromBody] Item item)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest("Not valid!"));
     }
     _itemRepository.AddItem(item);
     return(Ok(item));
 }
示例#11
0
 public IActionResult create(Item item)
 {
     if (item != null)
     {
         _itemRepository.AddItem(item);
         return(RedirectToAction("index"));
     }
     return(View(item));
 }
示例#12
0
        public IActionResult Post(string itemtype, string subtype, [FromBody] object ItemTypeObj)
        {
            var result = (IDictionary <string, object>)_respository.AddItem(ItemTypeObj, itemtype, subtype);

            Console.WriteLine("---- result ----");
            Console.WriteLine(result.ToString());
            Console.WriteLine(result["ITEMID"]);
            ///Console.WriteLine(result.ITEMID);

            return(Created($"/api/item/{itemtype}/{subtype}/{result["ITEMID"]}", result["ITEMID"]));
        }
示例#13
0
        public IHttpActionResult PostITEM(ITEMModel item)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            string poNo = _itemRepository.AddItem(item);

            return(CreatedAtRoute("DefaultApi", new { id = item.ITCODE }, item));
        }
示例#14
0
 public async Task <Item> AddNewItem(Item item)
 {
     try
     {
         return(await itemRepository.AddItem(item));
     }
     catch (Exception)
     {
         throw;
     }
 }
示例#15
0
        public HttpResponseMessage AddItem(int SubcatId, Item newItem)
        {
            if (string.IsNullOrWhiteSpace(newItem.Title))
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid Item name."));
            }

            _itemRepository.AddItem(SubcatId, newItem);

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
 public IActionResult Post(Items obj)
 {
     try
     {
         _repo.AddItem(obj);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(NotFound(ex.InnerException.Message));
     }
 }
 public IActionResult POST(Items item)
 {
     try
     {
         _repo.AddItem(item);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(NotFound(ex.InnerException.Message));
     }
 }
示例#18
0
 public IActionResult AddItem(Items items)
 {
     try
     {
         _repo.AddItem(items);
         return(Ok());
     }
     catch (Exception e)
     {
         return(NotFound(e.InnerException.Message));
     }
 }
示例#19
0
 /// <summary>
 /// Adds Item to database.
 /// </summary>
 /// <param name="item"></param>
 /// <returns>True if successful, otherwise fales.</returns>
 public bool AddItem(Item item)
 {
     try
     {
         itemRepo.AddItem(item);
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
示例#20
0
        public IActionResult AddItem(ItemModel item)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            _itemRepository.AddItem(item.Type, item.Amount);

            TempData["message"] = $"{item.Type} tipinde {item.Amount} tane Item eklendi.";

            return(RedirectToAction(nameof(Index)));
        }
示例#21
0
        private void btnSaveQuestion_Click(object sender, RoutedEventArgs e)
        {
            if (addOrEdit == 1)
            {
                item             = new Item();
                this.DataContext = item;

                try
                {
                    if (cboDataType.SelectedItem == null)
                    {
                        Jeeves.ShowMessage("Error", "Please select a data type");
                        return;
                    }
                    else if (txtNewSurveyQuestion.Text != "")
                    {
                        DataType selectedDataType = (DataType)cboDataType.SelectedItem;

                        item.ItemID    = Guid.NewGuid().ToString();
                        item.ItemName  = (string)txtNewSurveyQuestion.Text;
                        item.ValueType = selectedDataType.DisplayText;
                        itemRespository.AddItem(item);
                        ClearFields();
                    }
                }
                catch (Exception ex)
                {
                    Jeeves.ShowMessage("Error", ex.GetBaseException().Message.ToString());
                }
                addOrEdit = 0;
                tbkEnterQuestion.Visibility     = Visibility.Collapsed;
                txtNewSurveyQuestion.Visibility = Visibility.Collapsed;
                tbkDataType.Visibility          = Visibility.Collapsed;
                cboDataType.Visibility          = Visibility.Collapsed;
                rpSaveAndCancel.Visibility      = Visibility.Collapsed;
                ScreenUnlock();
                ClearFields();
                FillFields();
            }
            else
            {
                tbkEnterQuestion.Visibility     = Visibility.Collapsed;
                txtNewSurveyQuestion.Visibility = Visibility.Collapsed;
                tbkDataType.Visibility          = Visibility.Collapsed;
                cboDataType.Visibility          = Visibility.Collapsed;
                rpSaveAndCancel.Visibility      = Visibility.Collapsed;;
                SaveQuestion(selectedItem);
                selectedItem = null;
                addOrEdit    = 0;
            }
        }
示例#22
0
        public async Task <IActionResult> AddItem(ItemForCreateDto itemForCreateDto)
        {
            itemForCreateDto.Name = itemForCreateDto.Name.ToLower();

            var itemToCreate = new Item
            {
                Name        = itemForCreateDto.Name,
                Description = itemForCreateDto.Description
            };

            _repo.AddItem(itemToCreate);

            return((await _repo.SaveAll() == true) ? StatusCode(201) : BadRequest());
        }
示例#23
0
 public IActionResult AddItem([FromBody] Item newItem)
 {
     if (ModelState.IsValid)
     {
         _repo.AddItem(newItem);
         Response.StatusCode = (int)HttpStatusCode.OK;
         return(Json(new { success = true, message = "Item added!" }));
     }
     else
     {
         Response.StatusCode = (int)HttpStatusCode.BadRequest;
         return(Json(new { success = false, message = "Error in adding item" }));
     }
 }
示例#24
0
        public async Task <IActionResult> AddNewItem([FromBody] ItemViewModel item)
        {
            try
            {
                await _trasection.AddItem(item);

                return(Ok("Record Added Successfully"));
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  "Error occure during Adding"));
            }
        }
        private void btnSaveQuestion_Click(object sender, RoutedEventArgs e)
        {
            if (addOrEdit == 1)
            {
                item             = new Item();
                this.DataContext = item;

                try
                {
                    if (cboDataType.SelectedItem == null)
                    {
                        Jeeves.ShowMessage("Error", "Please select a data type");
                        return;
                    }
                    else if (txtNewSurveyQuestion.Text != "")
                    {
                        DataType selectedDataType = (DataType)cboDataType.SelectedItem;
                        App      userInfo         = (App)Application.Current;
                        item.ItemID         = Guid.NewGuid().ToString();
                        item.ItemName       = (string)txtNewSurveyQuestion.Text;
                        item.ValueType      = selectedDataType.DisplayText;
                        item.CreatedBy      = userInfo.userAccountName;
                        item.LastModifiedBy = userInfo.userAccountName;
                        itemRespository.AddItem(item);
                        NewAuditLine("Created by:" + userInfo.userAccountName + ", SurveyItem:" + item.ItemID + " " + item.ItemName + " " + item.ValueType + ", On Date: " + item.LastModifiedDate.ToString());
                        ClearFields();
                    }
                }
                catch (Exception ex)
                {
                    Jeeves.ShowMessage("Error", ex.GetBaseException().Message.ToString());
                }
                addOrEdit = 0;
                ScreenUnlock();
                ClearFields();
                FillFields(displayChoice);
            }
            else
            {
                App userInfo = (App)Application.Current;
                selectedItem.LastModifiedBy   = userInfo.userAccountName;
                selectedItem.LastModifiedDate = DateTime.Now;
                SaveQuestion(selectedItem);
                NewAuditLine("Modified(Edit) by:" + userInfo.userAccountName + ", SurveyItem:" + selectedItem.ItemID + " To: " + selectedItem.ItemName + " " + selectedItem.ValueType + ", On Date: " + selectedItem.LastModifiedDate.ToString());
                selectedItem = null;
                addOrEdit    = 0;
            }
        }
示例#26
0
 public IActionResult AddItem([FromBody] Item item)
 {
     try
     {
         var res = repo.AddItem(item);
         if (res == 0)
         {
             return(BadRequest());
         }
         return(Ok());
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
示例#27
0
        private Item Create(ItemViewModel item)
        {
            Item t = new Item
            {
                Name             = item.Name,
                Description      = item.Description,
                AddedByUserId    = UserInfo?.UserID ?? -1,
                ModifiedByUserId = UserInfo?.UserID ?? -1,
                DateAdded        = DateTime.UtcNow,
                DateModified     = DateTime.UtcNow,
                PortalId         = 0
            };

            _repository.AddItem(t);

            return(t);
        }
示例#28
0
        public async Task <IActionResult> AddItem([FromBody] ItemForAddDto item)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            List <ItemItemRelation> partsToAdd = new List <ItemItemRelation>();

            foreach (ItemItemRelationPartOfForGet part in item.Parts)
            {
                partsToAdd.Add(new ItemItemRelation {
                    Part   = part.Part,
                    Amount = part.Amount
                });
            }

            foreach (ItemItemRelation itemPart in partsToAdd)
            {
                var itemToReduce = await _repo.GetItem(itemPart.Part.Id);

                itemToReduce.Amount -= itemPart.Amount;
            }

            var itemToCreate = new Item(
                item.Placement,
                item.Amount,
                item.Template,
                item.Order,
                _userManager.FindByNameAsync(User.Identity.Name).Result,
                item.Properties,
                partsToAdd,
                item.PartOf,
                item.IsActive
                );

            bool result = await _repo.AddItem(itemToCreate);

            if (result)
            {
                User currentUser = _userManager.FindByNameAsync(User.Identity.Name).Result;
                result = await _eventLogRepo.AddEventLog(EventType.Created, "genstand", itemToCreate.Template.Name, itemToCreate.Id, currentUser);
            }
            return(result ? StatusCode(201) : BadRequest());
        }
        public ActionResult <Item> CreateItem(ItemDto item)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("One or more parameters are invalid"));
            }

            var reItem = _itemRepository.GetItemByName(item.Name);

            if (reItem != null)
            {
                return(Conflict("Error Occured"));
            }
            Item dbItem    = _mapper.Map <Item>(item);
            int  createdId = _itemRepository.AddItem(dbItem);

            return(CreatedAtAction(nameof(GetItem), new { id = createdId }, _mapper.Map <ItemDto>(dbItem)));
        }
        private Item Create(ItemViewModel item)
        {
            Item t = new Item
            {
                ItemName             = item.Name,
                ItemDescription      = item.Description,
                AssignedUserId       = item.AssignedUser,
                ModuleId             = ActiveModule.ModuleID,
                CreatedByUserId      = UserInfo.UserID,
                LastModifiedByUserId = UserInfo.UserID,
                CreatedOnDate        = DateTime.UtcNow,
                LastModifiedOnDate   = DateTime.UtcNow
            };

            _repository.AddItem(t);

            return(t);
        }