/********************************************************* #A This method gets a PriceOffer class to send to the user to update #B This loads the book with any existing Promotion #C I return either the existing Promotion for editing, or create a new one. The important point is to set the BookId, as we need to pass that through to the second stage * ******************************************************/ /// <summary> /// This deletes a promotion if the book has one, otherwise is adds a promotion /// </summary> /// <param name="promotion"></param> /// <returns></returns> public ValidationResult AddRemovePriceOffer(PriceOffer promotion) //#A { var book = _context.Books //#B .Include(r => r.Promotion) //#B .Single(k => k.BookId //#B == promotion.BookId); //#B if (book.Promotion != null) //#C { _context.Remove(book.Promotion); //#D _context.SaveChanges(); //#D return(null); //#E } if (string.IsNullOrEmpty(promotion.PromotionalText)) //#F { return(new ValidationResult( //#G "This field cannot be empty", //#G new [] { nameof(PriceOffer.PromotionalText) })); //#G } book.Promotion = promotion; //#H _context.SaveChanges(); //#I return(null); //#J }
private async Task SetOffers(List <Offer> offers) { foreach (Offer offer in offers) { OfferOrder offerOrder = null; PriceOffer priceOffer = null; try { if (!sqlCommandTools.CheckOffer(offer.id)) { offerOrder = new OfferOrder(); priceOffer = new PriceOffer(); priceOffer.DatateUpdate = DateTime.Now.ToString(); priceOffer.Price = offer.price; offerOrder.Id = offer.id; offerOrder.Description = offer.description; offerOrder.Id_category = offer.id_category; offerOrder.Name = offer.name; offerOrder.Store_id = offer.store_id; offerOrder.PriceOffers = new List <PriceOffer>(); offerOrder.PriceOffers.Add(priceOffer); sqlCommandTools.AddOffer(offerOrder); } } catch (Exception e) { File.AppendAllText("log/SetOffers.txt", $"{e.Message} {Environment.NewLine}"); } } }
public IActionResult ChangePromotion(PriceOffer dto, [FromServices] IChangePriceOfferService service) { Request.ThrowErrorIfNotLocal(); var book = service.UpdateBook(dto); SetupTraceInfo(); return(View("BookUpdated", "Successfully added/changed a promotion")); }
public void EditPriceOffer(PriceOffer offer) { var _offer = context.PriceOffers.Where <PriceOffer>(p => p.Id.Equals(offer.Id)).FirstOrDefault(); _offer.Discount = offer.Discount; _offer.StartDate = offer.StartDate; _offer.EndDate = offer.EndDate; context.SubmitChanges(); }
public async void AddPrice(string idOffer, PriceOffer priceOffer) { OfferOrder offerOrder = context.OfferOrders.Include(o => o.PriceOffers).First(o => o.Id == idOffer); if (offerOrder.PriceOffers == null) { offerOrder.PriceOffers = new List <PriceOffer>(); } offerOrder.PriceOffers.Add(priceOffer); await context.SaveChangesAsync(); }
protected void SaveDiscount(object sender, EventArgs e) { var _priceoffer = new PriceOffer { StartDate = startdate.Value, EndDate = endDate.Value, Discount = Convert.ToInt32(discountId.Value), }; client.createPriceOffer(_priceoffer, Convert.ToInt32(ProductDropDownList.SelectedItem.Value)); }
protected void EditDiscount(object sender, EventArgs e) { var discount = new PriceOffer { Id = Convert.ToInt32(prodId), Discount = Convert.ToDecimal(discountId.Value), StartDate = startdate.Value, EndDate = endDate.Value, }; client.EditPriceOffer(discount); }
public IActionResult AddOffer(PriceOffer f) { var user = User.FindFirst(ClaimTypes.NameIdentifier); Photographer edited = context.Photographers.Where(p => p.Users.Id == user.Value).FirstOrDefault(); //Photographer edited = context.Photographers.Where(p => p.OffersList.Where(f => f.Of_ID == f.Of_ID).FirstOrDefault().Of_ID == f.Of_ID).FirstOrDefault(); if (ModelState != null) { context.PriceOffers.ToList(); var p = context.Photographers.Where(p => p.OffersList.Where(o => o.Of_ID == f.Of_ID).FirstOrDefault().Of_ID == f.Of_ID).FirstOrDefault(); string wwwPath = this.Environment.WebRootPath; string contentPath = this.Environment.ContentRootPath; string path = Path.Combine(this.Environment.WebRootPath, "Images"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } List <string> uploadedFiles = new List <string>(); if (f.ImageFilePath != null) { foreach (IFormFile postedFile in f.ImageFilePath) { string fileName = Path.GetFileName(postedFile.FileName); using (FileStream stream = new FileStream(Path.Combine(path, fileName), FileMode.Create)) { postedFile.CopyTo(stream); uploadedFiles.Add(fileName); string imgP = "/Images/" + fileName; edited.OffersList.Add(new PriceOffer() { OfferTitle = f.OfferTitle, OfferDetails = f.OfferDetails, OfferEndDate = f.OfferEndDate, OfferImgPath = imgP, OffersPrice = f.OffersPrice }); context.SaveChanges(); return(RedirectToAction("TestPhoEdit", new { id = edited.Ph_Id })); } } } else { edited.OffersList.Add(new PriceOffer() { OfferTitle = f.OfferTitle, OfferDetails = f.OfferDetails, OfferEndDate = f.OfferEndDate, OfferImgPath = "/Images/22.jpg", OffersPrice = f.OffersPrice }); context.SaveChanges(); return(RedirectToAction("TestPhoEdit", new { id = edited.Ph_Id })); } } return(View(f)); }
public void createPriceOffer(PriceOffer priceOffer, int prodId) { var newPriceOffer = new PriceOffer { Id = priceOffer.Id, StartDate = priceOffer.StartDate, EndDate = priceOffer.EndDate, Status = priceOffer.Status, Discount = priceOffer.Discount, ProductId = prodId }; context.PriceOffers.InsertOnSubmit(newPriceOffer); context.SubmitChanges(); }
public PriceOffer getPriceOffer(int offerid) { var getOffer = context.PriceOffers.Where <PriceOffer>(o => o.Id.Equals(offerid)).FirstOrDefault(); var _offer = new PriceOffer { Id = getOffer.Id, StartDate = getOffer.StartDate, EndDate = getOffer.EndDate, Discount = getOffer.Discount, Status = getOffer.Status, ProductId = getOffer.ProductId }; return(_offer); }
public IActionResult ChangePromotion(PriceOffer dto, [FromServices] IChangePriceOfferService service) { Request.ThrowErrorIfNotLocal(); var error = service.AddRemovePriceOffer(dto); if (error != null) { ModelState.AddModelError(error.MemberNames.First(), error.ErrorMessage); return(View(dto)); } SetupTraceInfo(); return(View("BookUpdated", "Successfully added/changed a promotion")); }
public IActionResult UpdateOffers(PriceOffer f) { if (ModelState != null) { context.PriceOffers.ToList(); var p = context.Photographers.Where(p => p.OffersList.Where(o => o.Of_ID == f.Of_ID).FirstOrDefault().Of_ID == f.Of_ID).FirstOrDefault(); string wwwPath = this.Environment.WebRootPath; string contentPath = this.Environment.ContentRootPath; string path = Path.Combine(this.Environment.WebRootPath, "Images"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } List <string> uploadedFiles = new List <string>(); if (f.ImageFilePath != null) { foreach (IFormFile postedFile in f.ImageFilePath) { string fileName = Path.GetFileName(postedFile.FileName); using (FileStream stream = new FileStream(Path.Combine(path, fileName), FileMode.Create)) { postedFile.CopyTo(stream); uploadedFiles.Add(fileName); string imgP = "/Images/" + fileName; var edited = context.PriceOffers.Where(of => of.Of_ID == f.Of_ID).FirstOrDefault(); edited.OfferTitle = f.OfferTitle; edited.OfferDetails = f.OfferDetails; edited.OffersPrice = f.OffersPrice; edited.OfferImgPath = imgP; context.SaveChanges(); return(RedirectToAction("TestPhoEdit", new { id = p.Ph_Id })); } } } else { var edited = context.PriceOffers.Where(of => of.Of_ID == f.Of_ID).FirstOrDefault(); edited.OfferTitle = f.OfferTitle; edited.OfferDetails = f.OfferDetails; edited.OffersPrice = f.OffersPrice; context.SaveChanges(); return(RedirectToAction("TestPhoEdit", new { id = p.Ph_Id })); } } return(View(f)); }
public List <PriceOffer> getPriceOffers() { var list = new List <PriceOffer>(); var getPriceOffers = context.PriceOffers.ToList <PriceOffer>(); foreach (var p in getPriceOffers) { var _priceoffer = new PriceOffer { Id = p.Id, StartDate = p.StartDate, EndDate = p.EndDate, Status = p.Status, Discount = p.Discount, ProductId = p.ProductId }; list.Add(_priceoffer); } return(list); }
public Book UpdateBook(PriceOffer priceOffer) { var bookToUpdate = dataContex.Books .Include(book => book.Promotion) .Single(book => book.BookId == priceOffer.BookId); if (bookToUpdate.Promotion == null) { bookToUpdate.Promotion = priceOffer; } else { bookToUpdate.Promotion.PromotionalText = priceOffer.PromotionalText; bookToUpdate.Promotion.NewPrice = priceOffer.NewPrice; } dataContex.SaveChanges(); return(bookToUpdate); }
public Book Update(PriceOffer priceOffer) { var book = _context.Books. Include(b => b.Promotion). Single(b => b.BookId == priceOffer.BookId); if (book?.Promotion == null) { book.Promotion = priceOffer; } else { book.Promotion.NewPrice = priceOffer.NewPrice; book.Promotion.PromotionalText = priceOffer.PromotionalText; } _context.SaveChanges(); return(book); }
public IActionResult PhoRequest(int id, PhotographerRequest p, string Offer) { PriceOffer prof = context.PriceOffers.Where(o => o.OfferTitle == Offer).FirstOrDefault(); PhotographerRequest pr = new PhotographerRequest(); var user = User.FindFirst(ClaimTypes.NameIdentifier); Photographer po = context.Photographers.Where(p => p.Ph_Id == id).FirstOrDefault(); context.Users.ToList(); var member = context.Members.Where(m => m.Users.Id == user.Value).FirstOrDefault(); pr.RequestPhotographer = po; pr.PriceOffer = prof; pr.Date = p.Date; pr.RequestUser = member; pr.Message = p.Message; pr.Status = "Pending"; context.PhotographerRequests.Add(pr); context.SaveChanges(); return(RedirectToAction("TestPhoView", new { id = id })); }
public Book UpdateBook(PriceOffer promotion) //#D { var book = _context.Books //#E .Include(r => r.Promotion) //#E .Single(k => k.BookId //#E == promotion.BookId); //#E if (book.Promotion == null) //#F { book.Promotion = promotion; //#G } else { book.Promotion.NewPrice //#H = promotion.NewPrice; //#H book.Promotion.PromotionalText //#H = promotion.PromotionalText; //#H } _context.SaveChanges(); //#I return(book); //#J }
public IActionResult RemoveOffer(int Of_ID) { context.PriceOffers.ToList(); var user = User.FindFirst(ClaimTypes.NameIdentifier); Photographer pho = context.Photographers.Where(p => p.Users.Id == user.Value).FirstOrDefault(); PhotographerRequest ps = context.PhotographerRequests.Where(p => p.PriceOffer.Of_ID == Of_ID).FirstOrDefault(); if (ps == null) { PriceOffer pr = context.PriceOffers.Find(Of_ID); pho.OffersList.Remove(pr); context.PriceOffers.Remove(pr); context.SaveChanges(); return(RedirectToAction("TestPhoEdit", new { id = pho.Ph_Id })); } else { TempData["err"] = "this offer can't be deleted it used by some members"; return(RedirectToAction("TestPhoEdit", new { id = pho.Ph_Id })); } }
public void UpdatePromotionalPrice(Dto.PromotionalPriceFormDto promotionalPriceFormDto, int bookId) { var priceOffer = bookDbContext.Books .Where(x => x.BookId == bookId) .Select(x => x.Promotion) .SingleOrDefault(); if (priceOffer == null) { priceOffer = new PriceOffer(); priceOffer.BookId = bookId; bookDbContext.PricesOffers.Add(priceOffer); } priceOffer.NewPrice = promotionalPriceFormDto.Price.Value; priceOffer.StartDate = promotionalPriceFormDto.StartDate.Value; priceOffer.EndDate = promotionalPriceFormDto.EndDate.Value; bookDbContext.SaveChanges(); }
private async Task <OfferOrder> GetOfferOrder(string idShiping) { OfferOrder offerOrder1 = null; if (sqlCommandTools.CheckOffer(idShiping)) { offerOrder1 = sqlCommandTools.GetOfferOrder(idShiping); } else { OfferOrder offerOrder = new OfferOrder(); PriceOffer priceOffer = new PriceOffer(); priceOffer.DatateUpdate = DateTime.Now.ToString(); offerOrder.Id = idShiping; offerOrder.Store_id = 0; offerOrder.Name = "New"; offerOrder.PriceOffers = new List <PriceOffer>(); offerOrder.PriceOffers.Add(priceOffer); sqlCommandTools.AddOffer(offerOrder); } return(offerOrder1); }
public void TestDeletePriceOfferQuicklyOk() { //SETUP int priceOfferId; var options = SqliteInMemory.CreateOptions <EfCoreContext>(); using var context = new EfCoreContext(options); context.Database.EnsureCreated(); var book = new Book { Title = "Test Book", Promotion = new PriceOffer { NewPrice = 1 } }; context.Add(book); context.SaveChanges(); priceOfferId = book.Promotion.PriceOfferId; context.Books.Count().ShouldEqual(1); context.PriceOffers.Count().ShouldEqual(1); context.ChangeTracker.Clear(); //ATTEMPT var pOfferToDelete = new PriceOffer { PriceOfferId = priceOfferId }; context.Remove(pOfferToDelete); context.SaveChanges(); context.ChangeTracker.Clear(); //VERIFY context.Books.Count().ShouldEqual(1); context.PriceOffers.Count().ShouldEqual(0); }
private async void WorkUpdatePrice() { List <OfferOrder> offerOrders = sqlCommandTools.GetOfferOrders(); for (int i = 0; i < offerOrders.Count; i++) { try { if (sqlCommandTools.CheckPrice(offerOrders[i].Id)) { PriceOffer priceOffer = new PriceOffer(); priceOffer.DatateUpdate = DateTime.Now.ToString(); Offer offer = connectorEPN.GetOffer(offerOrders[i].Id); priceOffer.Price = offer.price; sqlCommandTools.AddPrice(offer.id, priceOffer); } } catch (Exception e) { File.AppendAllText("log/WorkUpdatePrice.txt", $"{e.Message} {Environment.NewLine}"); } } }
/// <summary> /// Creates a new price offer with the specified parameters. /// </summary> /// <param name="header">The headline for the price extension.</param> /// <param name="description">The detailed description line that may show on the price /// extension.</param> /// <param name="priceInMicros">The price to display, measured in micros /// (e.g. 1_000_000 micros = 1 USD).</param> /// <param name="currencyCode">The currency code representing the unit of currency.</param> /// <param name="unit">Optionally set a unit describing the quantity obtained for the /// price.</param> /// <param name="finalUrl">The final URL to which a click on the price extension drives /// traffic.</param> /// <param name="finalMobileUrl">The final URL to which mobile clicks on the price /// extension drives traffic.</param> /// <returns></returns> private PriceOffer CreatePriceOffer(string header, string description, int priceInMicros, string currencyCode, PriceExtensionPriceUnit unit, string finalUrl, string finalMobileUrl) { PriceOffer priceOffer = new PriceOffer() { Header = header, Description = description, FinalUrls = { finalUrl }, Price = new Money() { AmountMicros = priceInMicros, CurrencyCode = currencyCode }, Unit = unit }; // Optional: Sets the final mobile URLs. if (!string.IsNullOrEmpty(finalMobileUrl)) { priceOffer.FinalMobileUrls.Add(finalMobileUrl); } return(priceOffer); }
public static void CreateStockQuote(PriceOffer priceOffer) { dataManager.CreateStockQuotes(priceOffer.lotCode, Convert.ToDecimal(priceOffer.lotPriceOffer), priceOffer.firmName, priceOffer.offerTime); }