public int Create(ItemCreateDTO entityToCreate) { try { string query = @" INSERT INTO Items(ItemCode,SubGroupID,ItemName,ItemDescription,ItemUnitPrice,ItemUnitPriceWithMaxDiscount,ItemAvailableQty,ItemReorderQtyReminder,ItemImageFilename,IsFeaturedItem) VALUES (@ItemCode,@SubGroupID,@ItemName,@ItemDescription,@ItemUnitPrice,@ItemUnitPriceWithMaxDiscount,@ItemAvailableQty,@ItemReorderQtyReminder,@ItemImageFilename,@IsFeaturedItem) SELECT SCOPE_IDENTITY()"; var queryParameters = new DynamicParameters(); queryParameters.Add("@ItemCode", entityToCreate.ItemCode); queryParameters.Add("@SubGroupID", entityToCreate.SubGroupID); queryParameters.Add("@ItemName", entityToCreate.ItemName); queryParameters.Add("@ItemDescription", entityToCreate.ItemDescription); queryParameters.Add("@ItemUnitPrice", entityToCreate.ItemUnitPrice); queryParameters.Add("@ItemUnitPriceWithMaxDiscount", entityToCreate.ItemUnitPriceWithMaxDiscount); queryParameters.Add("@ItemAvailableQty", entityToCreate.ItemAvailableQty); queryParameters.Add("@ItemReorderQtyReminder", entityToCreate.ItemReorderQtyReminder); queryParameters.Add("@ItemImageFilename", ""); //Set Image to empty as this is available through the image update function. queryParameters.Add("@IsFeaturedItem", entityToCreate.IsFeaturedItem ? 1 : 0); return(Connection.QueryFirst <int>(query, queryParameters, CurrentTrans)); } catch (Exception ex) { throw SqlExceptionHandler.HandleSqlException(ex) ?? ex; } }
public async Task <IActionResult> Create([FromBody] ItemCreateDTO itemDTO) { try { _logger.LogInfo("Attempted to create Item"); if (itemDTO == null) { _logger.LogWarn($"Empty request submitted"); return(BadRequest()); } if (!ModelState.IsValid) { _logger.LogWarn($"Invalid request submitted"); return(BadRequest(ModelState)); } var item = _mapper.Map <Item>(itemDTO); var isSuccess = await _itemRepository.Create(item); if (!isSuccess) { return(ServerError("Item creation failed")); } _logger.LogInfo("Item created"); return(Created("", new { item })); } catch (Exception e) { return(ServerError(e)); } }
public async Task <IActionResult> Create(ItemCreateIndexView model) { try { if (ModelState.IsValid) { var Unit = await _unitRepo.GetById(model.UnitId).ConfigureAwait(true); var item = new ItemCreateDTO { ItemName = model.ItemName, Price = model.Price, Unit = Unit }; await _itemService.Create(item).ConfigureAwait(true); _toastNotification.AddSuccessToastMessage("Successfully Created Item :- " + item.ItemName); return(RedirectToAction("Index")); } } catch (Exception ex) { model.Units = (await _unitRepo.GetAllAsync().ConfigureAwait(true)).Where(a => a.IsActive()).ToList(); _toastNotification.AddErrorToastMessage(ex.Message); } return(View(model)); }
public async Task <ItemDTO> PutAsync(ItemCreateDTO item) { this.Logger.LogTrace($"{nameof(this.PutAsync)} called"); var result = await this.ItemCreateService.CreateAsync(this.Mapper.Map <ItemUpdateModel>(item)); return(this.Mapper.Map <ItemDTO>(result)); }
public async Task <ItemDTO> CreateItem(ItemCreateDTO newItem) { using (_unitOfWork) { Item item = _mapper.Map <ItemCreateDTO, Item>(newItem); User user = await _unitOfWork.UserRepository.GetUserWithItems(newItem.UserId); Trip trip = await _unitOfWork.TripRepository.GetTripWithItemsAndMembers(newItem.TripId); if (!trip.Travelers.Contains(user)) { return(null); } item.User = user; item.Trip = trip; if (user.MyItems == null) { user.MyItems = new List <Item>(); } user.MyItems.Add(item); if (trip.ItemList == null) { trip.ItemList = new List <Item>(); } trip.ItemList.Add(item); await _unitOfWork.ItemRepository.Create(item); _unitOfWork.UserRepository.Update(user); _unitOfWork.TripRepository.Update(trip); Notification notification = new Notification(); notification.Seen = false; notification.RelatedObjectName = item.Name; notification.Type = NotificationType.AddedItem; notification.User = user; notification.UserId = user.UserId; await _unitOfWork.NotificationRepository.Create(notification); await _unitOfWork.Save(); ItemDTO retItem = _mapper.Map <Item, ItemDTO>(item); await _messageControllerService.NotifyOnTripChanges(newItem.TripId, "AddItem", retItem); NotificationItemDTO notificationItem = new NotificationItemDTO() { Notification = _mapper.Map <Notification, NotificationDTO>(notification), Item = retItem }; await _messageControllerService.SendNotification(newItem.UserId, "AddItemNotification", notificationItem); return(retItem); } }
public ItemServiceTest() { unit = new Unit("as"); _itemService = new ItemService(_itemRepo.Object); _createDto = new ItemCreateDTO(); _updateDto = new ItemUpdateDTO(); _item = new Item(unit, item_name, 10); }
public async Task Create(ItemCreateDTO dto) { using var tx = TransactionScopeHelper.GetInstance(); var item = new Item(dto.Unit, dto.ItemName, dto.Price); await _itemRepo.InsertAsync(item); tx.Complete(); }
public ItemDTO Create(ItemCreateDTO modelToCreate) { try { int newID = UOW.ItemRepo.Create(modelToCreate); var createResult = UOW.ItemRepo.GetByID(newID); UOW.SaveChanges(); return(createResult); } catch (Exception ex) { UOW.RollbackChanges(); throw ex; } }
public async Task <IActionResult> Update(int id, [FromBody] ItemCreateDTO itemDTO) { try { _logger.LogInfo("Attempted to update Item"); if (id < 1) { _logger.LogWarn($"Invalid id submitted: {id}"); return(BadRequest()); } if (itemDTO == null) { _logger.LogWarn($"Empty request submitted"); return(BadRequest()); } var exists = await _itemRepository.Exists(id); if (!exists) { _logger.LogWarn($"Item with id {id} was not found"); return(NotFound()); } if (!ModelState.IsValid) { _logger.LogWarn($"Invalid request submitted"); return(BadRequest(ModelState)); } var item = _mapper.Map <Item>(itemDTO); // force item.Id to be id passed in item.Id = id; var isSuccess = await _itemRepository.Update(item); if (!isSuccess) { return(ServerError("Item update failed")); } _logger.LogInfo("Item updated"); return(Ok(new { item })); } catch (Exception e) { return(ServerError(e)); } }
public async Task <ActionResult> CreateItem([FromBody] ItemCreateDTO newItem) { try { if (!await _editRightsService.HasEditRights(newItem.TripId)) { return(BadRequest(new JsonResult("You can't currently edit this trip."))); } ItemDTO result = await _itemService.CreateItem(newItem); await _editRightsService.ProlongEditRights(newItem.TripId, _redisAppSettings.EditRightsProlongedTTL); if (result != null) { return(Ok(result)); } return(BadRequest()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public ActionResult <ItemDTO> Create([FromBody] ItemCreateDTO userInput) { try { return(_itemManager.Create(userInput)); } catch (BaseCustomException ex) { return(BadRequest(ex.Message)); } }
public ItemDTO Create(ItemCreateDTO modelToCreate) { return(_itemService.Create(modelToCreate)); }