public void Delete(BouquetBindingModel model) { using (var context = new FlowerShopDatabase()) { using (var transaction = context.Database.BeginTransaction()) { try { context.FlowerBouquets.RemoveRange(context.FlowerBouquets.Where(rec => rec.BouquetId == model.Id)); context.PackagingBouquets.RemoveRange(context.PackagingBouquets.Where(rec => rec.BouquetId == model.Id)); Bouquet element = context.Bouquets.FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Bouquets.Remove(element); context.SaveChanges(); } else { CheckingElement(element); } transaction.Commit(); } catch (Exception) { transaction.Rollback(); throw; } } } }
/// <summary> /// Конструктор класса <see cref="Bouquet"/> /// </summary> public static void DefBouquet() { Bouquet bouquet1 = new Bouquet(); int counter = 0; // вызов одноименных методов //bouquet1.Note(); //((IPaper)bouquet1).Note(); ((IPaper)bouquet1).Color = "Красный"; bouquet1.Price = 17.4F; bouquet1.Flowers = new List <Flower>(); bouquet1.Flowers.AddFlower(); Console.WriteLine("--------------------------------------"); Console.WriteLine($"Цвет обертки букета: {bouquet1.Color}\nЦена букета: {bouquet1.Price}\n"); foreach (var flower in bouquet1.Flowers) { Console.WriteLine($"{counter}) {flower.Name} {flower.Size} {flower.Color}"); counter++; } Console.WriteLine("--------------------------------------"); bouquet1.Flowers.DeleteFlower(); }
public void RemoveItemFromSessionCart(ISession session, Bouquet bouquet) { CartViewModel sessionCart = this.GetCartFromSession(session); sessionCart.items.Remove(bouquet); session.SetObjectAsJson("cart", sessionCart); }
/// <summary> /// Сортировки листа /// </summary> public static void CallSort() { Bouquet bouquet = new Bouquet(); ((IPaper)bouquet).Color = "Красный"; bouquet.Price = 16.26F; bouquet.Flowers = new List <Flower>() { new Flower { Name = "Цветок 1", Color = (Colors)2, Size = 5 }, new Flower { Name = "Цветок 2", Color = (Colors)2, Size = 4 }, new Flower { Name = "Цветок 3", Color = (Colors)3, Size = 3 }, new Flower { Name = "Цветок 4", Color = (Colors)4, Size = 2 }, new Flower { Name = "Цветок 5", Color = (Colors)5, Size = 1 } }; BouquetController.SortListByParam(bouquet); BouquetController.FindByColor(bouquet); }
public static void DefBouquet() { Bouquet bouquet1 = new Bouquet(); // вызов одноименных методов bouquet1.Note(); ((IPaper)bouquet1).Note(); bouquet1.Color = "Красный"; bouquet1.Price = 17.4F; bouquet1.SeNumberOfFlowers(ref bouquet1.flowers, 3); Console.WriteLine("--------------------------------------"); Console.WriteLine($"Цвет обертки букета: {bouquet1.Color}\nЦена букета: {bouquet1.Price}\n"); int counter = 1; foreach (var flwr in bouquet1.flowers) { Console.WriteLine($"Цветок {counter++}\nНазвание цветка: {flwr.Name}\nРазмер цветка: {flwr.Size}\n"); } Console.WriteLine("--------------------------------------"); //Bouquet bouquet2 = new Bouquet(); //bouquet2.Color = "Красный"; //bouquet2.Price = 17.4F; //bouquet2.SeNumberOfFlowers(ref bouquet2.flowers, 1); }
public async Task <ActionResult> PostBouquet(Bouquet bouquet) { database.Bouquets.Add(bouquet); await database.SaveChangesAsync(); return(Accepted()); }
public IActionResult RemoveBouquet(string bouquetId) { ISession session = HttpContext.Session; Bouquet bouquet = _bouquetStorage.FindById(bouquetId); _sessionCartStorage.RemoveItemFromSessionCart(session, bouquet); return(RedirectToAction("Index", "Cart")); }
public Bouquet Update(Bouquet updatedBouquet) { var bouquet = context.Bouquets.Attach(updatedBouquet); bouquet.State = Microsoft.EntityFrameworkCore.EntityState.Modified; context.SaveChanges(); return(updatedBouquet); }
public IActionResult RemoveItem(string bouquetId) { ISession session = HttpContext.Session; Bouquet bouquet = this.bouquetManager.GetBouquetById(bouquetId); this.sessionCartService.RemoveItemFromSessionCart(session, bouquet); return(RedirectToAction("Index", "Cart")); }
public ActionResult DeleteConfirmed(int id) { Bouquet bouquet = db.Bouquets.Find(id); db.Bouquets.Remove(bouquet); db.SaveChanges(); return(RedirectToAction("Index")); }
public void RemoveBouquetById(string id) { Bouquet bouquet = this.GetBouquetById(id); if (bouquet != null) { this.bouquetStorage.RemoveBouquet(bouquet); } }
//edit/put internal Bouquet Edit(Bouquet updatedBouquet) { Bouquet found = Get(updatedBouquet.Id); found.Name = updatedBouquet.Name; found.Description = updatedBouquet.Description != null ? updatedBouquet.Description : found.Description; found.Price = updatedBouquet.Price != 0 ? updatedBouquet.Price : found.Price; return(_repo.Edit(found)); }
//create/post internal Bouquet Create(Bouquet newBouquet) { Bouquet created = _repo.Create(newBouquet); if (created == null) { throw new Exception("Create Request Failed"); } return(created); }
//Get by id internal Bouquet Get(int id) { Bouquet found = _repo.Get(id); if (found == null) { throw new Exception("Invalid Id"); } return(found); }
public ActionResult Edit([Bind(Include = "BouquetID,BouquetName,Description,Price")] Bouquet bouquet) { if (ModelState.IsValid) { db.Entry(bouquet).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(bouquet)); }
public ActionResult Edit([Bind(Include = "BouquetId,BouquetName")] BouquetViewModel bouquetModel) { if (ModelState.IsValid) { var bouquet = new Bouquet(); bouquet.Name = bouquetModel.BouquetName; _bouquetService.Update(bouquet); return(RedirectToAction("Index")); } return(View(bouquetModel)); }
public ActionResult <Bouquet> EditBouquet(int id, Bouquet bouquet) { string query = @" UPDATE bouquets SET name = @Name WHERE id = @Id; SELECT * FROM bouquets WHERE id = @Id; "; return(_db.QueryFirstOrDefault <Bouquet>(query, bouquet)); }
public Bouquet Create(Bouquet value) { string query = @" INSERT INTO bouquets (name, storeId) VALUES (@Name, @StoreId); SELECT LAST_INSERT_ID();"; int id = _db.ExecuteScalar <int>(query, value); value.Id = id; return(value); }
public Bouquet GetById(int id) { string query = "SELECT * FROM bouquets WHERE id = @id"; Bouquet bouquet = _db.QueryFirstOrDefault <Bouquet>(query, new { id }); if (bouquet == null) { throw new Exception("Invalid Id"); } return(bouquet); }
public void AddToSessionCart(ISession session, Bouquet bouquet) { var sessionCart = session.GetObjectFromJson <CartViewModel>("cart"); if (sessionCart == null) { sessionCart = new CartViewModel(); } sessionCart.items.Add(bouquet); session.SetObjectAsJson("cart", sessionCart); }
public ActionResult <Bouquet> Create([FromBody] Bouquet newBouquet) { try { return(Ok(_bs.Create(newBouquet))); } catch (Exception e) { return(BadRequest(e.Message)); } }
//Post internal Bouquet Create(Bouquet newBouquet) { string sql = @" INSERT INTO bouquets (name, description, price) VALUES (@Name, @Description, @Price); SELECT LAST_INSERT_ID(); "; newBouquet.Id = _db.ExecuteScalar <int>(sql, newBouquet); return(newBouquet); }
public Bouquet Delete(int id) { Bouquet bouquet = context.Bouquets.Find(id); if (bouquet != null) { context.Bouquets.Remove(bouquet); context.SaveChanges(); } return(bouquet); }
public ActionResult Create([Bind(Include = "BouquetID,BouquetName,Description,Price")] Bouquet bouquet) { if (ModelState.IsValid) { db.Bouquets.Add(bouquet); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(bouquet)); }
public ActionResult <Bouquet> Post([FromBody] Bouquet value) { try { return(Ok(_repo.Create(value))); } catch (Exception e) { return(BadRequest(e)); } }
public Bouquet Update(Bouquet value) { string query = @" UPDATE bouquets SET name = @Name, storeId = @StoreId WHERE id = @Id; SELECT * FROM bouquets WHERE id = @Id"; return(_db.QueryFirstOrDefault <Bouquet>(query, value)); }
public ActionResult <Bouquet> Edit(int id, [FromBody] Bouquet updatedBouquet) { try { updatedBouquet.Id = id; return(Ok(_bs.Edit(updatedBouquet))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task <IActionResult> PutBouquet(int id, Bouquet bouquet) { if (id != bouquet.Id) { return(BadRequest()); } database.Entry(bouquet).State = EntityState.Modified; await database.SaveChangesAsync(); return(NoContent()); }
public ActionResult <Bouquet> Put(int id, [FromBody] Bouquet value) { try { value.Id = id; return(Ok(_repo.Update(value))); } catch (Exception e) { return(BadRequest(e)); } }
/// <summary> /// <para>Работа с объектом через ссылку на интерфейс и абстрактный класс</para> /// <para>Работа is и as</para> /// </summary> public static void ObjViaRefInterface() { IPaper paper = new Bouquet(); paper.Color = "Зеленый"; Console.WriteLine($"\nЦвет: {paper.Color}"); paper.Note(); Plant plant = new Bouquet(); plant.Name = "Ромашка"; Console.WriteLine($"\nНазвание: {plant.Name}"); plant.Note(); Plant plant1 = new Rose(); plant1.Name = "Роза"; plant1.Size = 2.43; Console.WriteLine($"\nНазвание: {plant1.Name}\nРазмер: {plant1.Size}"); plant1.Note(); Console.WriteLine($"{plant1.ToString()}"); Flower flower = new Flower(); Bouquet bouquet = new Bouquet(); int num = 2; //bool checkFlower = flower is Flower; //bool checkBouquet = bouquet is Bouquet; //bool checkNum = num is Flower; bool checkFlower = bouquet is Flower; bool checkBouquet = flower is Bouquet; Console.WriteLine($"\ncheckFlower: {checkBouquet}\ncheckBouquet: {checkFlower}\ncheckNum:"); try { Flower flower1 = new Flower(); Rose rose = flower1 as Rose; Console.WriteLine($"\n{rose.GetType()}"); } catch (NullReferenceException e) { Console.WriteLine(e); } Rose rose1 = new Rose(); Flower flower2 = rose1 as Flower; Console.WriteLine($"\n{flower2.GetType()}"); }
public BouquetDTO(Bouquet b) { this.IsNew = b.IsNew; this.Id = b.Id; this.ImgUrl = b.ImgUrl; this.Name = b.Name; this.Url = this.Name.RemoveDiacritics(); this.Description = b.Description; Components = new List<ComponentDTO>(); Sizes = new List<SizeDTO>(); if(b.BouquetSizes != null) foreach(var s in b.BouquetSizes) this.Sizes.Add(new SizeDTO(s)); if (b.Components != null) foreach (var s in b.Components) this.Components.Add(new ComponentDTO(s)); }
/// <summary> /// Process the bouquet data. /// </summary> /// <param name="sections">A collection of MPEG2 sections containing the bouquet data.</param> protected override void ProcessBouquetSections(Collection<Mpeg2Section> sections) { foreach (Mpeg2Section section in sections) { if (RunParameters.Instance.TraceIDs.Contains("BOUQUETSECTIONS")) Logger.Instance.Dump("Bouquet Section", section.Data, section.Length); BouquetAssociationSection bouquetSection = BouquetAssociationSection.ProcessBouquetAssociationTable(section.Data); if (bouquetSection != null) { bool added = BouquetAssociationSection.AddSection(bouquetSection); if (added) { if (bouquetSection.TransportStreams != null) { foreach (TransportStream transportStream in bouquetSection.TransportStreams) { if (transportStream.Descriptors != null) { foreach (DescriptorBase descriptor in transportStream.Descriptors) { FreeSatChannelInfoDescriptor freeSatInfoDescriptor = descriptor as FreeSatChannelInfoDescriptor; if (freeSatInfoDescriptor != null) { if (freeSatInfoDescriptor.ChannelInfoEntries != null) { foreach (FreeSatChannelInfoEntry channelInfoEntry in freeSatInfoDescriptor.ChannelInfoEntries) { FreeSatChannel channel = new FreeSatChannel(); channel.OriginalNetworkID = transportStream.OriginalNetworkID; channel.TransportStreamID = transportStream.TransportStreamID; channel.ServiceID = channelInfoEntry.ServiceID; channel.UserChannel = channelInfoEntry.UserNumber; channel.Unknown1 = channelInfoEntry.Unknown1; channel.Unknown2 = channelInfoEntry.Unknown2; channel.BouquetID = bouquetSection.BouquetID; FreeSatChannel.AddChannel(channel); Bouquet bouquet = Bouquet.FindBouquet(channel.BouquetID); if (bouquet == null) { bouquet = new Bouquet(channel.BouquetID, BouquetAssociationSection.FindBouquetName(channel.BouquetID)); Bouquet.AddBouquet(bouquet); } Region region = bouquet.FindRegion(channel.Region); if (region == null) { region = new Region(string.Empty, channel.Region); bouquet.AddRegion(region); } region.AddChannel(channel); } } } } } } } } } } }
private void processFreeviewInfoDescriptor(FreeviewChannelInfoDescriptor freeviewInfoDescriptor, int originalNetworkID, int transportStreamID, int bouquetID) { if (freeviewInfoDescriptor.ChannelInfoEntries == null) return; if (openTVChannels != 0) return; foreach (FreeviewChannelInfoEntry channelInfoEntry in freeviewInfoDescriptor.ChannelInfoEntries) { EITChannel channel = new EITChannel(); channel.OriginalNetworkID = originalNetworkID; channel.TransportStreamID = transportStreamID; channel.ServiceID = channelInfoEntry.ServiceID; channel.UserChannel = channelInfoEntry.UserNumber; channel.Flags = channelInfoEntry.Flags; channel.BouquetID = bouquetID; EITChannel.AddChannel(channel); eitChannels++; Bouquet bouquet = Bouquet.FindBouquet(channel.BouquetID); if (bouquet == null) { bouquet = new Bouquet(channel.BouquetID, BouquetAssociationSection.FindBouquetName(channel.BouquetID)); Bouquet.AddBouquet(bouquet); } Region region = bouquet.FindRegion(channel.Region); if (region == null) { region = new Region(string.Empty, channel.Region); bouquet.AddRegion(region); } region.AddChannel(channel); } }
private void processOpenTVInfoDescriptor(OpenTVChannelInfoDescriptor openTVInfoDescriptor, int originalNetworkID, int transportStreamID, int bouquetID) { if (openTVInfoDescriptor.ChannelInfoEntries == null) return; if (eitChannels != 0) { OpenTVChannel.Channels.Clear(); eitChannels = 0; return; } foreach (OpenTVChannelInfoEntry channelInfoEntry in openTVInfoDescriptor.ChannelInfoEntries) { OpenTVChannel channel = new OpenTVChannel(); channel.OriginalNetworkID = originalNetworkID; channel.TransportStreamID = transportStreamID; channel.ServiceID = channelInfoEntry.ServiceID; channel.ChannelID = channelInfoEntry.ChannelID; channel.UserChannel = channelInfoEntry.UserNumber; channel.Type = channelInfoEntry.Type; channel.Flags = channelInfoEntry.Flags; channel.BouquetID = bouquetID; channel.Region = openTVInfoDescriptor.Region; OpenTVChannel.AddChannel(channel); openTVChannels++; Bouquet bouquet = Bouquet.FindBouquet(channel.BouquetID); if (bouquet == null) { bouquet = new Bouquet(channel.BouquetID, BouquetAssociationSection.FindBouquetName(channel.BouquetID)); Bouquet.AddBouquet(bouquet); } Region region = bouquet.FindRegion(channel.Region); if (region == null) { region = new Region(string.Empty, channel.Region); bouquet.AddRegion(region); } region.AddChannel(channel); } }
/// <summary> /// Process the bouquet data. /// </summary> /// <param name="sections">A collection of MPEG2 sections containing the bouquet data.</param> protected override void ProcessBouquetSections(Collection<Mpeg2Section> sections) { foreach (Mpeg2Section section in sections) { BouquetAssociationSection bouquetSection = BouquetAssociationSection.ProcessBouquetAssociationTable(section.Data); if (bouquetSection != null) { bool added = BouquetAssociationSection.AddSection(bouquetSection); if (added) { if (bouquetSection.TransportStreams != null) { foreach (TransportStream transportStream in bouquetSection.TransportStreams) { if (transportStream.Descriptors != null) { foreach (DescriptorBase descriptor in transportStream.Descriptors) { OpenTVChannelInfoDescriptor infoDescriptor = descriptor as OpenTVChannelInfoDescriptor; if (infoDescriptor != null) { if (infoDescriptor.ChannelInfoEntries != null) { foreach (OpenTVChannelInfoEntry channelInfoEntry in infoDescriptor.ChannelInfoEntries) { OpenTVChannel channel = new OpenTVChannel(); channel.OriginalNetworkID = transportStream.OriginalNetworkID; channel.TransportStreamID = transportStream.TransportStreamID; channel.ServiceID = channelInfoEntry.ServiceID; channel.ChannelID = channelInfoEntry.ChannelID; channel.UserChannel = channelInfoEntry.UserNumber; channel.Type = channelInfoEntry.Type; channel.Flags = channelInfoEntry.Flags; channel.BouquetID = bouquetSection.BouquetID; channel.Region = infoDescriptor.Region; OpenTVChannel.AddChannel(channel); Bouquet bouquet = Bouquet.FindBouquet(channel.BouquetID); if (bouquet == null) { bouquet = new Bouquet(channel.BouquetID, BouquetAssociationSection.FindBouquetName(channel.BouquetID)); Bouquet.AddBouquet(bouquet); } Region region = bouquet.FindRegion(channel.Region); if (region == null) { region = new Region(string.Empty, channel.Region); bouquet.AddRegion(region); } region.AddChannel(channel); } } } } } } } } } } }
/// <summary> /// Add a bouquet to the collection. /// </summary> /// <param name="newBouquet">The bouquet to be added.</param> public static void AddBouquet(Bouquet newBouquet) { foreach (Bouquet oldBouquet in Bouquets) { if (oldBouquet.BouquetID == newBouquet.BouquetID && oldBouquet.Region == newBouquet.Region) return; } bouquets.Add(newBouquet); }
private static void addBouquetInNameOrder(Collection<Bouquet> sortedBouquets, Bouquet newBouquet) { foreach (Bouquet oldBouquet in sortedBouquets) { if (oldBouquet.Name.CompareTo(newBouquet.Name) > 0) { sortedBouquets.Insert(sortedBouquets.IndexOf(oldBouquet), newBouquet); return; } } sortedBouquets.Add(newBouquet); }