//TODO: create new sorting + UserEntrySortings public void CreateSorting(UserListSortingDto dto, IList <ProductDto> products) { int sortingId = _listSortingRepository.Create(ConvertDtoToDB(dto)); for (int x = 0; x < products.Count(); x++) { Nullable <int> prevEntryId = null; if (x > 0) { prevEntryId = products[x - 1].Id; } Nullable <int> nextEntryId = null; if (x < products.Count() - 1) { nextEntryId = products[x + 1].Id; } UserEntrySorting entrySorting = new UserEntrySorting { UserListSorting_Id = sortingId, ShoppingListEntry_Id = products[x].Id, PrevEntryId_Id = prevEntryId, NextEntryId_Id = nextEntryId }; _entrySortingRepository.Create(entrySorting); } ShoppingListService shoppingListService = new ShoppingListService(); ShoppingListDto shoppingList = new ShoppingListDto(); shoppingList.Id = dto.ShoppingList_Id; shoppingList.ChosenSortingId = sortingId; shoppingListService.Update(shoppingList); }
public ActionResult ShareList(FormCollection collection) { try { var emailAddress = collection["EmailAddress"]; var type = int.Parse(collection["Type"]); var listId = int.Parse(collection["ShoppingList_Id"]); UserService userService = new UserService(); var userId = userService.GetIdByEmail(emailAddress); ShoppingListDto shoppingListDto = new ShoppingListDto { UserId = userId, Id = listId, ListAccessTypeId = type }; ShoppingListService listService = new ShoppingListService(); listService.CreateLink(shoppingListDto); TempData["SuccessMessage"] = "You successfully shared your list!"; return(RedirectToAction("SingleList", new { @id = listId })); } catch { var listId = int.Parse(collection["ShoppingList_Id"]); TempData["ErrorMessage"] = "An error occured and your list hasn't been shared."; return(RedirectToAction("SingleList", new { @id = listId })); } }
public ActionResult CreateList(FormCollection collection) { try { var name = collection["listname"]; if (name == null || name == "") { throw new Exception("Name cannot be null."); } var sessionUserId = Session["UserId"]; int userid = int.Parse(sessionUserId.ToString()); ShoppingListDto list = new ShoppingListDto { Name = name, Path = "somerandomPath", ListAccessTypeId = 1, //Default owner when creating UserId = userid, ChosenSortingId = null }; ShoppingListService listService = new ShoppingListService(); listService.Create(list); TempData["SuccessMessage"] = "You successfully created a new shopping list!"; return(RedirectToAction("Lists")); } catch (Exception) { TempData["ErrorMessage"] = "Something went wrong. Make sure to have entered a valid list name. Try again!"; return(RedirectToAction("Lists")); } }
public ActionResult RenameList(FormCollection collection) { try { var newName = collection["ListName"]; int listId = int.Parse(collection["ShoppingList_Id"]); ShoppingListService listService = new ShoppingListService(); var dbList = listService.Get(listId); if (newName == dbList.Name) { throw new Exception("The name of the list is unchanged."); } ShoppingListDto list = new ShoppingListDto { Id = listId, Name = newName }; listService.Update(list); TempData["SuccessMessage"] = "The list's name was successfully updated!"; return(Redirect(Request.UrlReferrer.ToString())); } catch { TempData["ErrorMessage"] = "Updating the list's name wasn't successful."; return(Redirect(Request.UrlReferrer.ToString())); } }
public async Task StartAsync(IDialogContext context) { try { var shoppingList = new ShoppingListDto() { Id = new Guid(), Items = new List <ShoppingItemDto>() }; context.UserData.SetValue("CurrentShoppingListId", shoppingList.Id); await context.PostAsync(MessagesResource.CreatedList); await context.PostAsync(MessagesResource.AskWhatToAdd); context.Call(_dialogFactory.Create <GetProductsByUserTask>(), Callback); } catch (Exception ex) { await context.PostAsync(MessagesResource.CourtesyError); context.Call(_dialogFactory.Create <GreetingDialog>(), Callback); } }
public async Task <IActionResult> Create(ShoppingListDto shoppingListDto) { var shoppingListToCreate = new ShoppingList { Name = shoppingListDto.Name, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now }; var createdUser = await _userRepository.CreateShoppingListAsync(shoppingListToCreate, 1); return(Ok()); }
public async Task StartAsync(IDialogContext context) { try { var shoppingList = new ShoppingListDto() { Id = new Guid(), Items = new List <ShoppingItemDto>() { new ShoppingItemDto() { CategoryId = 3034, Color = Pin.Gray, Description = "pasta", Id = context.UserData.Get <Guid>("CurrentShoppingListId") }, new ShoppingItemDto() { CategoryId = 3034, Color = Pin.Gray, Description = "vino", Id = context.UserData.Get <Guid>("CurrentShoppingListId") }, new ShoppingItemDto() { CategoryId = 3034, Color = Pin.Gray, Description = "pizza", Id = context.UserData.Get <Guid>("CurrentShoppingListId") } } }; if (shoppingList == null) { shoppingList = new ShoppingListDto() { Id = new Guid(), Items = new List <ShoppingItemDto>() }; await context.PostAsync(MessagesResource.EmptyShoppingList); await context.PostAsync(MessagesResource.AskWhatToAdd); context.Call(_dialogFactory.Create <GetProductsByUserTask>(), Callback); } else { if (shoppingList.Items.Count == 0) { await context.PostAsync(MessagesResource.EmptyShoppingList); } else { context.UserData.SetValue("CurrentShoppingListId", shoppingList.Id); await context.PostAsync(MessagesResource.ShowShoppingListReview); var sb = new StringBuilder(); foreach (var item in shoppingList.Items) { sb.Append(item.Description + "\n\n"); } await context.PostAsync(sb.ToString()); } context.Call(_dialogFactory.Create <AskIfAddAnotherProductTask>(), Callback); } } catch (Exception ex) { await context.PostAsync(MessagesResource.CourtesyError); context.Call(_dialogFactory.Create <GreetingDialog>(), Callback); } }
public ActionResult EditItem(FormCollection collection) { try { var name = collection["Name"]; var reusable = collection["UserProduct"]; var price = decimal.Parse(collection["Price"]); var listId = int.Parse(collection["ListId"]); var qty = uint.Parse(collection["Quantity"]); var unitTypeId = int.Parse(collection["UnitTypesListId"]); int catId = 0; int userCatId = 0; if (collection["CategoryListId"] != "") { catId = int.Parse(collection["CategoryListId"]); } var userCat = collection["UserCategory"]; var currencyId = int.Parse(collection["CurrencyListId"]); var prodTypeId = int.Parse(collection["ProductTypeId"]); var prodId = int.Parse(collection["ProductId"]); /* UPDATING ShoppingListEntry */ ShoppingListEntryService entryService = new ShoppingListEntryService(); ShoppingListEntryDto entry = new ShoppingListEntryDto { Id = entryService.GetEntryId(prodId, listId), Quantity = (int)qty, ProductTypeId = prodTypeId, ShoppingList_Id = listId, Product_Id = prodId, State_Id = 2 //Default is unchecked }; entryService.Update(entry); //updates ShoppingListEntry /* CREATE NEW UserCatgory */ if (userCat != "") { LanguageService languageService = new LanguageService(); CategoryDto category = new CategoryDto { Name = userCat, LanguageId = languageService.GetByCode(Session["LanguageCode"].ToString()).Id, UserId = int.Parse(Session["UserId"].ToString()) }; CategoryService categoryService = new CategoryService(); userCatId = categoryService.Create(category); } ProductService productService = new ProductService(); if (prodTypeId == 4 || prodTypeId == 3) { if (reusable == "false") { prodTypeId = 4; //4 = UserListProduct = non reusable } else { prodTypeId = 3; } /* UPDATING UserProduct */ UserProductDto userProduct = new UserProductDto { Id = productService.GetUserProductId(prodId), ProductId = prodId, Name = name }; if (userCat != "") { userProduct.Category_Id = userCatId; } else { userProduct.Category_Id = catId; } userProduct.User_Id = int.Parse(Session["UserId"].ToString()); userProduct.Unit_Id = unitTypeId; userProduct.Price = price; userProduct.Currency_Id = currencyId; productService.Update(userProduct); } else if (prodTypeId == 1) //if default Product { if (catId != 0) { //create LinkDefaultProductToCategory entry } else if (userCatId != 0) { //create LinkDefaultProductToCategory entry } } /* UPDATING Product -> for new Timestamp*/ ProductDto productDto = new ProductDto { Id = prodId, ProductTypeId = prodTypeId }; productService.Update(productDto); /* UPDATING ShoppingList -> for new Timestamp: */ ShoppingListDto shoppingList = new ShoppingListDto { Id = listId }; ShoppingListService listService = new ShoppingListService(); listService.Update(shoppingList); TempData["SuccessMessage"] = "Successfully edited this item"; return(RedirectToAction("SingleList", new { @id = listId })); } catch { TempData["ErrorMessage"] = "There was an error while editing the item"; return(Redirect(Request.UrlReferrer.ToString())); } }
public ActionResult CreateItem(FormCollection collection) { try { var name = collection["Name"]; var reusable = collection["UserProduct"]; var price = decimal.Parse(collection["Price"]); var listId = int.Parse(collection["ShoppingList_Id"]); var qty = int.Parse(collection["quantity"]); var unitTypeId = int.Parse(collection["UnitTypesListId"]); //TODO: create lists in view and get id (like for countries/languages) var catId = int.Parse(collection["CategoryListId"]); var userCat = collection["UserCategory"]; int userCatId = 0; var currencyId = int.Parse(collection["CurrencyListId"]); int prodType = 0; var prodId = 0; var chosenProductId = collection["ChosenProductId"]; //gets defaultProductId from dropdown if (name != "" && chosenProductId != "") //Name filled in and defaultProduct chosen { throw new Exception("You can either create a new item or choose from the default products, but not both!"); } LanguageService languageService = new LanguageService(); if (userCat != "") { CategoryDto category = new CategoryDto { Name = userCat, LanguageId = languageService.GetByCode(Session["LanguageCode"].ToString()).Id, UserId = int.Parse(Session["UserId"].ToString()) }; CategoryService categoryService = new CategoryService(); userCatId = categoryService.Create(category); } ShoppingListEntryService entryService = new ShoppingListEntryService(); ProductService productService = new ProductService(); if (name != "") //IF UserProduct -> create Product - ShoppingListEntry - UserProduct { if (reusable == "false") { prodType = 4; //4 = UserListProduct = non reusable } else { prodType = 3; //reusable UserProduct } //create a new Product ProductDto productDto = new ProductDto { ProductTypeId = prodType }; prodId = productService.Create(productDto); //create new UserProduct UserProductDto userProduct = new UserProductDto { ProductId = prodId, Name = name }; if (userCat != "") { userProduct.Category_Id = userCatId; } else { userProduct.Category_Id = catId; } userProduct.User_Id = int.Parse(Session["UserId"].ToString()); userProduct.Unit_Id = unitTypeId; userProduct.Price = price; userProduct.Currency_Id = currencyId; entryService.Create(userProduct); } else if (chosenProductId != "") //IF DefaultProduct -> create ShoppingListEntry & LinkDefaultProductToUser { //check if chosen defaultProduct or reusable UserProduct prodId = int.Parse(chosenProductId); prodType = productService.GetProductTypeId(prodId); if (prodType == 1) //if DefaultProduct: create Link entry { DefaultProductDto defaultProductDto = new DefaultProductDto { Id = productService.GetDefaultProductId(prodId) }; productService.CreateLink(defaultProductDto, int.Parse(Session["UserId"].ToString())); } //if reusable UserProduct: only create ShoppingListEntry } //create Entry if not existent right now! var existentEntries = entryService.GetEntriesByListId(listId); foreach (ShoppingListEntryDto shoppingListEntry in existentEntries) { if (shoppingListEntry.Product_Id == prodId) { throw new Exception("You can't add the same product to your list twice."); } } ShoppingListEntryDto entry = new ShoppingListEntryDto { Quantity = qty, Product_Id = prodId, ShoppingList_Id = listId, State_Id = 2 //Default is unchecked }; entryService.Create(entry); //Update ShoppingList to update Timestamp: ShoppingListDto shoppingList = new ShoppingListDto { Id = listId }; ShoppingListService listService = new ShoppingListService(); listService.Update(shoppingList); // Update Sorting var listEntries = productService.GetEntriesAsProducts(listId, languageService.GetByCode(Session["LanguageCode"].ToString()).Id); UserListSortingService listSortingService = new UserListSortingService(); var sortingId = listService.Get(listId, int.Parse(Session["UserId"].ToString())).ChosenSortingId; UserListSortingDto sorting = new UserListSortingDto(); if (sortingId != null) { sorting.Id = (int)sortingId; } sorting.ShoppingList_Id = listId; listSortingService.SaveSorting(sorting, listEntries); TempData["SuccessMessage"] = "Successfully created a new item"; return(RedirectToAction("SingleList", new { @id = listId })); } catch { TempData["ErrorMessage"] = "There was an error while creating a new item. Be aware that you can only create a new item or choose from the dropdown list of default products and your own reusable items, but you can't do both."; return(Redirect(Request.UrlReferrer.ToString())); } }
public async Task GetTask(IDialogContext context, IAwaitable <IMessageActivity> result) { try { var message = await result; var luisResult = await LuisHelper.GetIntentAndEntitiesFromLUIS(message.Text); var product = context.UserData.GetValue <ProductDto>("SelectedCategoryPromoProduct"); switch (luisResult.TopScoringIntent.Intent) { case LuisIntent.CreateNewList: case LuisIntent.OpenLastList: { if (luisResult.TopScoringIntent.Intent == LuisIntent.CreateNewList) { var shoppingList = new ShoppingListDto() { Id = new Guid(), Items = new List <ShoppingItemDto>() { new ShoppingItemDto() { CategoryId = 3034, Color = Pin.Gray, Description = "pasta", Id = context.UserData.Get <Guid>("CurrentShoppingListId") }, new ShoppingItemDto() { CategoryId = 3034, Color = Pin.Gray, Description = "vino", Id = context.UserData.Get <Guid>("CurrentShoppingListId") }, new ShoppingItemDto() { CategoryId = 3034, Color = Pin.Gray, Description = "pizza", Id = context.UserData.Get <Guid>("CurrentShoppingListId") } } }; context.UserData.SetValue("CurrentShoppingListId", shoppingList.Id); } context.Call(_dialogFactory.Create <AskIfAddAnotherProductTask>(), Callback); break; } default: { var handler = new HandleUserIncorrectInput(context); if (handler.CheckCounterErrors()) { await handler.UserErrorLimitExceeded(); context.Call(_dialogFactory.Create <GreetingDialog>(), Callback); } else { await context.PostAsync(MessagesResource.CourtesyChooseError); var sender = new SendCorrectListChooseCard(context); await sender.Send(); context.Wait(GetTask); } break; } } } catch (Exception ex) { await context.PostAsync(MessagesResource.CourtesyError); context.Call(_dialogFactory.Create <GreetingDialog>(), Callback); } }
public List <ShoppingListDto> GetAllShoppingList(ShoppingListDto input) { return(_unitOfWork.ShoppingLists.GetAllShoppingList(input)); }
public async Task GetShoppingListForEdit(ShoppingListDto input) { await _unitOfWork.ShoppingLists.GetShoppingListForEdit(input); }
public async Task CreateOrEditShoppingList(ShoppingListDto input) { await _unitOfWork.ShoppingLists.CreateOrEditShoppingList(input); }
public async Task StartAsync(IDialogContext context) { try { var currentShoppingList = new ShoppingListDto() { Id = new Guid(), Items = new List <ShoppingItemDto>() { new ShoppingItemDto() { CategoryId = 3034, Color = Pin.Gray, Description = "pasta", Id = context.UserData.Get <Guid>("CurrentShoppingListId") }, new ShoppingItemDto() { CategoryId = 3034, Color = Pin.Gray, Description = "vino", Id = context.UserData.Get <Guid>("CurrentShoppingListId") }, new ShoppingItemDto() { CategoryId = 3034, Color = Pin.Gray, Description = "pizza", Id = context.UserData.Get <Guid>("CurrentShoppingListId") } } }; var categories = currentShoppingList.Items.Select(x => x.CategoryId).ToList(); var products = new List <ProductDto>() { new ProductDto() { CategoryId = 3034, Description = "prodotto 1", Id = 1, SKU = "1" }, new ProductDto() { CategoryId = 3034, Description = "prodotto 2", Id = 2, SKU = "2" }, new ProductDto() { CategoryId = 3034, Description = "prodotto 3", Id = 3, SKU = "3" }, new ProductDto() { CategoryId = 3034, Description = "prodotto 4", Id = 4, SKU = "4" } }; if (products == null || products.Count == 0) { context.Call(_dialogFactory.Create <AskIfWantProductPositionTask>(), Callback); } else { context.UserData.SetValue("LastPromoProducts", products); await context.PostAsync(MessagesResource.PromoProducts); var sender = new SendCorrectProductsListCard(context); await sender.Send(products); new HandleUserIncorrectInput(context).ResetCounter(); context.Wait(GetTask); } } catch (Exception ex) { await context.PostAsync(MessagesResource.CourtesyError); context.Call(_dialogFactory.Create <GreetingDialog>(), Callback); } }