public async Task <Response> Handle(Request request, CancellationToken cancellationToken) { var check = _context.Shoppings.FirstOrDefault(x => x.Name == request.Shopping.Name); if (check != null) { throw new Exception("Shopping with the same name already exist"); } var data = new Shopping { Id = Guid.NewGuid(), Name = request.Shopping.Name, CreatedDate = request.Shopping.CretedDate }; await _context.Shoppings.AddAsync(data, cancellationToken); await _context.SaveChangesAsync(cancellationToken); var response = new Response { Data = new DataResponse { CretedDate = data.CreatedDate, Id = data.Id, Name = data.Name } }; return(response); }
public void VerifyThatTheMostExpensiveProductsAreEliminatedFromTheCart() { Shopping.ShoppingCart[] expectedCart = new Shopping.ShoppingCart[] { new Shopping.ShoppingCart { product = "bananaaaaas", price = 10 }, new Shopping.ShoppingCart { product = "apples", price = 3 }, new Shopping.ShoppingCart { product = "pears", price = 3 }, new Shopping.ShoppingCart { product = "oranges", price = 11 }, new Shopping.ShoppingCart { product = "lemons", price = 11 }, new Shopping.ShoppingCart { product = "cherries", price = 25 }, }; Shopping.ShoppingCart[] newCart = Shopping.EliminateTheMostExpensiveProduct(cart); Assert.AreEqual(expectedCart.Length, newCart.Length); CollectionAssert.AreEqual(expectedCart, newCart); }
public ActionResult Edit(int id) { Shopping shopping = db.Shoppings.Find(id); ViewBag.Shoppings = shopping; return(View()); }
public async Task <ActionResult <Shopping> > PostShopping(Shopping shopping) { _context.Shopping.Add(shopping); await _context.SaveChangesAsync(); return(CreatedAtAction("GetShopping", new { id = shopping.id }, shopping)); }
static void Main(string[] args) { Shopping alto_palermo = 5; Comerciante a = new Comerciante("Alberto", "Samudio"); Comerciante b = new Comerciante("Juan", "Leirado"); Exportador e1 = new Exportador("Electrónica 80", 15200f, "Domingo", "Caballo", ETipoProducto.Tecnologico); Importador i1 = new Importador("Granola S.A.", 23900f, a, EPaises.UnionEuropea); Exportador e2 = new Exportador("Matarife", 29095f, "Joe", "Molleja", ETipoProducto.Rural); Importador i2 = new Importador("Matarife", 203000f, a, EPaises.Taiwan); Importador i3 = new Importador("Matarife", 98000f, a, EPaises.China); Importador i4 = new Importador("Matarife", 10350f, b, EPaises.UnionEuropea); alto_palermo += e1; alto_palermo += e1; alto_palermo += i1; alto_palermo += e2; alto_palermo += i2; alto_palermo += i3; alto_palermo += i4; Console.WriteLine(Shopping.Mostrar(alto_palermo)); Console.ReadLine(); }
public ActionResult Empty() { var c = Shopping.GetCart(this.HttpContext); c.Empty(); return(RedirectToAction("Index")); }
public async Task <ShoppingResult> CreateListItem(Shopping shopping) { var result = new ShoppingResult(); try { if (!String.IsNullOrEmpty(shopping.Description)) { _shoppingListDataAccess.CreateListItem(shopping); result.ResultCode = ShoppingCodes.Success; } else { result.Message = "There's no item"; result.ResultCode = ShoppingCodes.BadRequest; } } catch (Exception ex) { result.ResultCode = ShoppingCodes.InternalServerError; result.Message = ex.Message; this._logger.LogError(ex, ex.Message); //throw ex; } return(result); }
public void Post([FromBody] Shopping shopping) { string result = string.Empty; ShoppingRepository repository = new ShoppingRepository(); result = repository.DeleteShoppingById(shopping.Id_Trolley); }
public ActionResult Remove(int id) { var c = Shopping.GetCart(this.HttpContext); c.Remove(id); return(RedirectToAction("Index")); }
public void SaveShoopingMarket(Rootobject mall) { var model = new ShoppingType { Name = "AVM", CategoryId = 21 }; UnitOfWork.CurrentSession.ShoppingTypes.Add(model); foreach (var item in mall.response.venues) { var data = new Shopping { Name = item.name, ShoppingTypeId = model.Id, Lat = item.location.lat, Long = item.location.lng, Url = item.url ?? "", Phone = item.contact != null ? item.contact.phone : "", IconId = 16 }; UnitOfWork.CurrentSession.Shoppings.Add(data); } UnitOfWork.CurrentSession.SaveChanges(); }
public async Task <IActionResult> Edit(int id, [Bind("Id,CustomerId,DatePurchase,SumReciept,Photo")] Shopping shopping) { if (id != shopping.Id) { return(NotFound()); } var customers = await _context.Customers .SingleOrDefaultAsync(m => m.CustomerId == shopping.CustomerId); ViewData["customerName"] = customers.FirstName + " " + customers.LastName; if (ModelState.IsValid) { try { _context.Update(shopping); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ShippingExists(shopping.Id)) { return(NotFound()); } else { throw; } } return(View(shopping)); } return(RedirectToAction(nameof(Index))); }
public void SaveMarket(Rootobject market) { //var cat = new Category //{ // Name = "Alışveriş", // Color = "#ff9600" //}; //UnitOfWork.CurrentSession.Categories.Add(cat); var model = new ShoppingType { Name = "Market", CategoryId = 21, }; UnitOfWork.CurrentSession.ShoppingTypes.Add(model); foreach (var item in market.response.venues) { var data = new Shopping { Name = item.name, Lat = item.location.lat, Long = item.location.lng, Phone = item.contact != null ? item.contact.phone : "", Url = item.url ?? "", ShoppingTypeId = model.Id, IconId = 16 }; UnitOfWork.CurrentSession.Shoppings.Add(data); } UnitOfWork.CurrentSession.SaveChanges(); }
private static void Test(DriverOptions options) { var shopping = new Shopping(options); try { shopping.Driver.Manage().Window.Maximize(); shopping.AddSection("Test section 1"); shopping.Driver.Navigate().GoToUrl(shopping.Url.ToString()); shopping.AddFirstItemFromShoppingList("Test item 1", "Test section 1"); shopping.AddItemFromShoppingList("Test item 2", "Test section 1"); shopping.Driver.Navigate().GoToUrl(shopping.Url + @"/options"); shopping.AddItemFromOptions("Test item 3", "Test section 1"); shopping.Driver.Navigate().GoToUrl(shopping.Url + @"/sections"); shopping.AddItemFromSections("Test item 4", "Test section 1"); shopping.RemoveItem("Test item 1"); shopping.CrossOutItem("Test item 2"); shopping.EditItemName("Test item 2", "2nd test item"); shopping.AddSection("Test section 2"); shopping.EditItemSection("2nd test item", "Test section 2"); shopping.EditSectionName("Test section 2", "2nd test section"); shopping.RemoveSection("Test section 1"); shopping.RemoveAllItems(); shopping.Driver.Quit(); } catch (Exception e) { Console.WriteLine(e); shopping.Driver.Quit(); } }
public HttpResponseMessage UpdateShopping(int ID, string Name, string Date) { try { DateTime DateCreate = DateTime.Now; try { DateCreate = DateTime.ParseExact(Date, "yyyy-MM-dd", CultureInfo.InvariantCulture); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message)); } Shopping Bll = new Shopping(); MShopping Model = new MShopping() { Id = ID, Name = Name, CreatedDate = DateCreate, }; var Data = Bll.InsertData(Model); return(Request.CreateResponse(HttpStatusCode.OK, Data)); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public Response GetAll(string listType) { try { List list = null; switch (listType) { case "missing": list = new Missing(); break; case "shopping": list = new Shopping(); break; } return(new SuccessResponse <ListModel[]> { results = list.GetAll() }); } catch (Exception e) { throw new Exception(e.Message); } }
public async Task <IActionResult> PutShopping(int id, Shopping shopping) { if (id != shopping.id) { return(BadRequest()); } _context.Entry(shopping).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ShoppingExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ShoppingResult> DeleteListItem(Shopping shopping) { var result = new ShoppingResult(); try { if (shopping != null) { if (shopping.IdItem != 0) { _shoppingListDataAccess.Delete(shopping); result.ResultCode = ShoppingCodes.Success; } } else { result.ResultCode = ShoppingCodes.BadRequest; } } catch (Exception ex) { result.ResultCode = ShoppingCodes.InternalServerError; this._logger.LogError(ex, ex.Message); throw ex; } return(result); }
public Response PartialUpdate(string listType, int foodId, [FromBody] ListModel body) { try { List list = null; switch (listType) { case "missing": list = new Missing(); break; case "shopping": list = new Shopping(); break; } return(new SuccessResponse <ListModel> { results = list.partialUpdate(foodId, body) }); } catch (Exception e) { throw new Exception(e.Message); } }
public HttpResponseMessage Put(int id, [FromBody] Shopping item) { try { using (CheckOutEntities entities = new CheckOutEntities()) { var entity = entities.Shoppings.FirstOrDefault(s => s.ID == id); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Item with id = " + id.ToString() + " not found")); } else { entity.ItemName = item.ItemName; entity.Quantity = item.Quantity; entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
//Adding items to user list public ActionResult AddToUserList(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Shopping shopping = db.Shoppings.Find(id); if (shopping == null) { return(HttpNotFound()); } UserManager <ApplicationUser> UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db)); ApplicationUser currentUser = UserManager.FindById(User.Identity.GetUserId()); UserList newlist = new UserList(); newlist.Title = shopping.Title; newlist.Description = shopping.Description; newlist.Link = shopping.Link; newlist.Location = shopping.Location; newlist.ListCategoryId = 5; //have to use # be sure to confirm the numbers in List Categories. newlist.UserName = currentUser; db.UserLists.Add(newlist); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Edit(Guid id, Shopping shopping) { if (id != shopping.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(shopping); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ShoppingExists(shopping.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CustomerId"] = new SelectList(_context.Customers, "Id", "Name", shopping.CustomerId); ViewData["ProductId"] = new SelectList(_context.Products, "Id", "Name", shopping.ProductId); return(View(shopping)); }
private void GetCategory() { Shopping shopping = new Shopping(); ddlCategory.DataSource = null; ddlCategory.DataSource = shopping.GetCategorie(); ddlCategory.DataBind(); }
public async Task <IActionResult> Patch([FromBody] Shopping shopping) { if (shopping != null) { return(Ok(await shopping.Update())); } return(BadRequest("Parameters are null")); }
public void VerifyTheAveragePrice() { double expectedAverage = 20.38; double average = Shopping.CalculateTheAverage(cart); Assert.AreEqual(expectedAverage, average); }
public void VerifyTotalPriceOfTheShoppingCart() { var expectedTotalPrice = 163; var totalPrice = Shopping.CalculateTotatlPriceOfTheShoppingCart(cart); Assert.AreEqual(expectedTotalPrice, totalPrice); }
public ActionResult DeleteConfirmed(int id) { Shopping shopping = db.Shoppings.Find(id); db.Shoppings.Remove(shopping); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult PutInCookie(string productid, string color, string size, string Quantity) { JavaScriptSerializer JSONSerializer = new JavaScriptSerializer(); var cookieName = "shoppingcar"; var productrepository = new ProductRepository(); var product = productrepository.FindProductFormatByProductID(int.Parse(productid)); var quantity = product.FirstOrDefault((x) => x.Color == color && x.Size == size); var s = new Shopping() { ProductID = quantity.ProductID, ProductName = quantity.ProductName, ProductImage = quantity.ProductImage, UnitPrice = quantity.UnitPrice, Description = quantity.Description, StockQuantity = quantity.StockQuantity, Size = quantity.Size, Color = quantity.Color, Quantity = int.Parse(Quantity), ProductFormatID = quantity.ProductFormatID }; if (quantity.StockQuantity == 0) { return(View("NoProductQuantity")); } else { if (Request.Cookies["shoppingcar"] == null) { var token = Guid.NewGuid().ToString(); var shopping = new List <Shopping>(); shopping.Add(s); //HttpContext.Application[token] = DateTime.UtcNow.AddHours(12); string json = JSONSerializer.Serialize(shopping); var hc = new HttpCookie(cookieName, HttpUtility.UrlEncode(json)) { Expires = DateTime.Now.AddMinutes(30), HttpOnly = true }; Response.Cookies.Add(hc); } else { string json = HttpUtility.UrlDecode(Request.Cookies["shoppingcar"].Value); var shopping = JSONSerializer.Deserialize <List <Shopping> >(json); shopping.Add(s); //HttpContext.Application[token] = DateTime.UtcNow.AddHours(12); string jsons = JSONSerializer.Serialize(shopping); var hc = new HttpCookie(cookieName, HttpUtility.UrlEncode(jsons)) { Expires = DateTime.Now.AddMinutes(30), HttpOnly = true }; Response.Cookies.Add(hc); } } return(RedirectToAction("Index", "Shopping")); }
public IActionResult Post([FromBody] Shopping item) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _shop.AddItem(item); return(StatusCode(StatusCodes.Status201Created)); }
public ActionResult ReviewInvoice() { Customer customer = db.Customers.Where(x => x.Username == User.Identity.Name).First(); Shopping cart = db.Shoppings.Where(x => x.CustomerID == customer.CustomerID).First(); Shipping ship = db.Shippings.Where(x => x.CustomerID == customer.CustomerID).First(); Billing bill = db.Billings.Where(x => x.CustomerID == customer.CustomerID).First(); Credit_Card card = db.Credit_Card.Where(x => x.CustomerID == customer.CustomerID).First(); List <Book> results = new List <Book>(); InvoiceModel invoice = new InvoiceModel(); invoice.Prices = new List <decimal>(); invoice.Amounts = new List <int>(); invoice.Publishers = new List <string>(); using (SqlConnection connection = new SqlConnection("data source=cs.cofo.edu;initial catalog=gvaught;persist security info=True;user id=gvaught;password=beargav;MultipleActiveResultSets=True;App=EntityFramework")) { SqlCommand cmd = new SqlCommand("usp_GetCart", connection); cmd.CommandType = CommandType.StoredProcedure; SqlParameter p1 = new SqlParameter("@cartID", SqlDbType.Int); SqlParameter p2 = new SqlParameter("@custID", SqlDbType.Int); p1.Value = cart.CartID; p2.Value = customer.CustomerID; cmd.Parameters.Add(p1); cmd.Parameters.Add(p2); connection.Open(); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { Book book = new Book(); book.BookID = (int)dr["BookID"]; book.Title = (string)dr["Title"]; book.ISBN = (string)dr["ISBN"]; book.PublisherID = (int)dr["PublisherID"]; book.PublishYear = (int)dr["PublishYear"]; book.PageNum = (int)dr["PageNum"]; book.Language = (string)dr["Language"]; book.Edition = (int)dr["Edition"]; book.CoverType = (string)dr["CoverType"]; invoice.Prices.Add((decimal)dr["Price"]); invoice.Amounts.Add((int)dr["Amount"]); int pubID = (int)dr["PublisherID"]; invoice.Publishers.Add(db.Publishers.Where(x => x.PublisherID == pubID).First().Name); results.Add(book); } connection.Close(); } invoice.Books = results.ToList(); invoice.Cart = cart; invoice.Shipping = ship; invoice.Billing = bill; invoice.Card = card; invoice.TotalPrice = cart.TotalPrice; return(View(invoice)); }
public ActionResult Edit([Bind(Include = "ShoppingID,ShoppingName,Address,Phone")] Shopping shopping) { if (ModelState.IsValid) { db.Entry(shopping).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(shopping)); }
public ShoppingConsoleUI() { shopping = new Shopping(); }
public SimpleItemType GetSingleItem(string itemID) { Shopping service = new Shopping(); service.Url = ConfigurationManager.AppSettings["ShoppingService"] + "?appid=" + ConfigurationManager.AppSettings["AppId"] + "&version=523&siteid=" + siteID + "&callname=GetSingleItem&responseencoding=SOAP&requestencoding=SOAP"; GetSingleItemRequestType multipleRequest = new GetSingleItemRequestType(); multipleRequest.IncludeSelector = "Details,ItemSpecifics,Variations"; multipleRequest.ItemID = itemID; GetSingleItemResponseType multipleResponse = service.GetSingleItem(multipleRequest); return multipleResponse.Item; }
public SimpleItemType[] GetMultipleItemsDetails(SearchResult result) { List<SimpleItemType> listSimpleItemType = new List<SimpleItemType>(); Shopping service = new Shopping(); service.Url = ConfigurationManager.AppSettings["ShoppingService"] + "?appid=" + ConfigurationManager.AppSettings["AppId"] + "&version=523&siteid=" + siteID + "&callname=GetMultipleItems&responseencoding=SOAP&requestencoding=SOAP"; int page = 0; int perPage = 20; int skip = 0; if(result.count > 40) { page = 3; } else if (result.count > 20 && result.count <= 40) { page = 2; } else { page = 1; } for (int i = 0; i < page; i++) { skip = i * perPage; var resultItems = result.item.Skip(skip).Take(perPage); List<String> items = new List<String>(); foreach (SearchItem item in resultItems) { items.Add(item.itemId); } System.Net.ServicePointManager.Expect100Continue = false; GetMultipleItemsRequestType multipleRequest = new GetMultipleItemsRequestType(); multipleRequest.IncludeSelector = "Details,ItemSpecifics,Variations"; multipleRequest.ItemID = items.ToArray(); GetMultipleItemsResponseType multipleResponse = service.GetMultipleItems(multipleRequest); listSimpleItemType.AddRange(multipleResponse.Item.ToList()); } return listSimpleItemType.ToArray(); }