/// <summary> /// Create a new shop /// </summary> /// <param name="s">Model Shop</param> /// <returns>bool</returns> public bool CreateNew(Shop s) { if (!ValidShopModel(s)) { return(false); } if (s.IsDelete == null) { s.IsDelete = false; } try { shopRepository.Add(s); this.unitOfWork.Commit(); } catch { return(false); } return(true); }
public async Task <IActionResult> AddItem([FromBody] ItemForCreateDto item) { var currentUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); var currentItem = new Item(); currentItem.User = _repo.GetUser(currentUserId).Result; currentItem.UserId = currentUserId; currentItem.Title = item.Title; currentItem.IsService = item.IsService; currentItem.Description = item.Description; currentItem.ShipingAddress = item.ShipingAddress; currentItem.ShipingCountry = item.ShipingCountry; currentItem.CreatedDate = DateTime.Now; currentItem.Quantity = int.Parse(item.Quantity); currentItem.UnitPrice = Double.Parse(item.UnitPrice); currentItem.OtherUrl = item.OtherUrl; _repo.Add(currentItem); if (await _repo.SaveAll()) { var itemFromRepo = _repo.GetItemsByUser(int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)).Result.Where(i => i.CreatedDate == currentItem.CreatedDate && i.Title == currentItem.Title).FirstOrDefault(); var itemToReturn = _mapper.Map <ItemForDetailsDto>(itemFromRepo); return(Ok(itemToReturn)); } throw new Exception("Failed to save item."); }
public async Task <IActionResult> CreateMessage(int userId, [FromBody] MessageForCreateDto msg) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var recipientId = _repo.GetUser(msg.RecipientId); //var if (recipientId == null) { return(BadRequest("Could not find recipient user.")); } if (_repo.GetItem(msg.AboutItemId) == null) { return(BadRequest("Item doesn't exist.")); } var message = _mapper.Map <Message>(msg); message.Sender = _repo.GetUser(userId).Result; _repo.Add(message); var messageToReturn = _mapper.Map <MessageToReturnDto>(message); if (await _repo.SaveAll()) { return(CreatedAtRoute("GetMessage", new { id = message.Id }, messageToReturn)); } return(BadRequest("Error while saving.")); }
static void Main(string[] args) { Console.WriteLine("Start!"); Shop shop = new Shop("Москва", "Шереметивская", 6); _shopRepository.Add(shop); Phone phone = new Phone(shop.Id, "mi8", "телефон среднего ценового класса", "процессор: Qualcomm Snapdragon 439, 2000МГц, 8-ми ядерный...", 20000); _phoneRepository.Add(phone); }
public async Task <ActionResult> Post([FromBody] ShopModel model) { var shop = new Shop() { Name = model.Name, Address = model.Address, Phone = model.Phone }; await _shopRepository.Add(shop); return(Ok()); }
public async Task <IActionResult> AddToCart(int userId, int itemId, int quantity) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var item = await _repo.GetItem(itemId); if (item == null) { return(NoContent()); } var currentCart = await _repo.GetCartItem(userId, itemId); if (currentCart != null) { currentCart.Quantity = currentCart.Quantity + quantity; } else { Cart cart = new Cart { UserId = userId, User = await _repo.GetUser(userId), ItemId = itemId, Item = item, Quantity = quantity }; _repo.Add(cart); } if (await _repo.SaveAll()) { return(NoContent()); } throw new Exception("Failed to add item to your cart."); }
public JsonResult PostShop(SuperAdminRequest request) { if (!isSuperAdmin(request.RootPassword)) { return(_Response.Forbid()); } Shop shop = request.Shop; if (!isShopValid(shop)) { return(_Response.BadRequest()); } shop = _db.Add(shop); return(_Response.Ok(shop)); }
public ActionResult Create(Shop shop) { try { if (ModelState.IsValid) { repository.Add(shop); return(RedirectToAction("Index")); } return(View("Edit")); } catch (Exception ex) { ModelState.AddModelError("FatalError", Helper.ErrorMessage(ex)); return(View("Edit")); } }
public async Task <IActionResult> CreateShop([FromBody] SaveShopResource shopResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var shop = mapper.Map <SaveShopResource, Shop>(shopResource); shop.LastUpdate = DateTime.Now; repository.Add(shop); await unitOfWork.CompleteAsync(); shop = await repository.GetShop(shop.Id); var result = mapper.Map <Shop, ShopResource>(shop); return(Ok(result)); }
public ActionResult Post([FromBody] ShopViewModel shop) { if (!ModelState.IsValid) { throw new HttpRequestException(string.Format( _errorHandler.GetMessage(ErrorMessagesEnum.ModelValidation), ModelState.Values.First().Errors.First().ErrorMessage)); } _shopRepository.Add(new Shop { Name = shop.Name, Location = new Point(shop.longitude, shop.latitude) { SRID = 4326 } }); return(Ok()); }
public async Task <IActionResult> AddFavorite(int id, int itemId) { if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var favorite = await _repo.GetFavorite(id, itemId); if (favorite != null) { return(BadRequest("This item is already one of your favorites.")); } if (await _repo.GetUser(id) == null) { return(NotFound("User not found")); } if (await _repo.GetItem(itemId) == null) { return(NotFound("Item not found")); } favorite = new FavoriteItem { UserId = id, ItemId = itemId }; _repo.Add <FavoriteItem>(favorite); if (await _repo.SaveAll()) { return(Ok()); } return(BadRequest("Error while saving.")); }
public async Task <IActionResult> PostCartItems(int userId, [FromBody] CartItem cartItem) { var cart = await _repo.GetCartByUserId(userId); if (cart == null) { return(BadRequest("Cart does not exist for the current user!")); } var existingCartItems = cart.CartItems; CartItem cartItemToAdd = cartItem; cartItemToAdd.CartId = cart.Id; var qunatity = 1; foreach (CartItem item in existingCartItems) { if (item.ProductId == cartItem.ProductId) { cartItemToAdd = item; qunatity = qunatity + item.Quantity; } } cartItemToAdd.Quantity = qunatity; if (cartItemToAdd.Quantity > 1) { _repo.UpdateCartItem(cartItemToAdd); } else { _repo.Add(cartItemToAdd); } var result = await _repo.SaveAllAsync(); return(Ok(result)); }
public async Task Handle(AddShopCommand message) { if (message == null) { throw new ArgumentNullException(nameof(message)); } var aggregate = new ShopAggregate { Id = message.Id, Subject = message.Subject, Name = message.Name, Description = message.Description, BannerImage = message.BannerImage, ProfileImage = message.ProfileImage, CategoryId = message.CategoryId, StreetAddress = message.StreetAddress, PostalCode = message.PostalCode, Locality = message.Locality, Country = message.Country, GooglePlaceId = message.GooglePlaceId, Longitude = message.Longitude, Latitude = message.Latitude, CreateDateTime = message.CreateDateTime, UpdateDateTime = message.UpdateDateTime, TagNames = message.TagNames }; if (message.ProductCategories != null) { aggregate.ProductCategories = message.ProductCategories.Select(p => new ShopProductCategory { Id = Guid.NewGuid().ToString(), Name = p.Name, Description = p.Description, CreateDateTime = DateTime.UtcNow, UpdateDateTime = DateTime.UtcNow }).ToList(); } if (message.ProductFilters != null) { aggregate.ShopFilters = message.ProductFilters.Select(f => new ShopFilter { Id = Guid.NewGuid().ToString(), Name = f.Name, Values = f.Values == null ? new List <ShopFilterValue>() : f.Values.Select(v => new ShopFilterValue { Id = Guid.NewGuid().ToString(), CreateDateTime = DateTime.UtcNow, UpdateDateTime = DateTime.UtcNow, Content = v }) }).ToList(); } await _shopRepository.Add(aggregate); _eventPublisher.Publish(new ShopAddedEvent { Subject = aggregate.Subject, ShopId = message.Id, Name = message.Name, Longitude = message.Longitude, Latitude = message.Latitude, CommonId = message.CommonId }); }
public void Add(ModelBL modelBL) { var model = Map(modelBL); _repository.Add(model); }
public void Execute(CreateShopModel model) { _shopRepo.Add(new Shop(model.Code, model.Name)); _uow.Save(); }
public void AddShop(Shop Shop, bool commit = true) { ShopRepository.Add(Shop); }
public int PostShop(ShopInputDTO item) { return(repository.Add(item)); }
public Shop Add(Shop shop) { return(_shopRepository.Add(shop)); }
public void Create(ShopMaster shop) { _shopRepository.Add(shop); _unitOfWork.Commit(); }