示例#1
0
 /// <summary>
 /// Load tags.
 /// </summary>
 private void InitializeTags()
 {
     if (!TagDB.Load(ref tags))
     {
         ShowErrorMessageBox(DatabaseError, "Loading tags failed!");
     }
 }
        /// <summary>
        /// Updates tags and dish-tag links
        /// </summary>
        /// <param name="dishTagNames">List of tag names for dish</param>
        /// <param name="dish">Dish</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        private async Task UpdateTagLinks(HashSet <TagToAdd> dishTagNames, DishDB dish, CancellationToken cancellationToken = default)
        {
            foreach (var item in dishTagNames)
            {
                TagDB tag = await _context.Tags.IgnoreQueryFilters().Where(_ => _.TagName == item.TagName).Select(_ => _).FirstOrDefaultAsync(cancellationToken);

                if (tag is null)
                {
                    var tagAfter = await _tagService.AddTagDBAsync(item);

                    dish.DishTags.Add(new DishTagDB {
                        TagId = tagAfter.Data.Id, DishId = dish.Id
                    });
                }
                else if (_context.Entry(tag).Property <bool>("IsDeleted").CurrentValue)
                {
                    _context.Entry(tag).Property <bool>("IsDeleted").CurrentValue = false;
                    dish.DishTags.Add(new DishTagDB {
                        TagId = tag.Id, DishId = dish.Id
                    });
                }
                else
                {
                    dish.DishTags.Add(new DishTagDB {
                        TagId = tag.Id, DishId = dish.Id
                    });
                }
            }
        }
示例#3
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        Item newItem = new Item();

        newItem.CategoryName  = CategoryDB.getCategorybyName("Services");
        newItem.Deposit       = Convert.ToDecimal(tbxRefundableDeposit.Text);
        newItem.Location      = LocationDB.getLocationbyID(ddlMRTLocation.SelectedValue);
        newItem.PricePerDay   = Convert.ToDecimal(tbxPricePerDay);
        newItem.PricePerWeek  = Convert.ToDecimal(tbxPricePerWeek);
        newItem.PricePerMonth = Convert.ToDecimal(tbxPricePerMonth);
        newItem.Renter        = MemberDB.getMemberbyEmail(Session["user"].ToString());
        newItem.Description   = tbxDescription.InnerText;
        newItem.PostedDate    = DateTime.Now;
        newItem.ItemID        = Utility.convertIdentitytoPK("ITM", ItemDB.addItem(newItem));

        List <string> tags = Utility.findHashTags(tbxDescription.InnerText);

        if (tags.Count > 0)
        {
            foreach (string t in tags)
            {
                if (!TagDB.isTagPresent(t))
                {
                    TagDB.addTag(t);
                }

                ItemTagDB.addItemTag(newItem, t);
            }
        }
    }
        public async Task <Result <IEnumerable <DishView> > > GetByTagIndexAsync(string tagName, CancellationToken cancellationToken = default)
        {
            TagDB tag = await _context.Tags.Where(_ => _.TagName == tagName).Select(_ => _).AsNoTracking().FirstOrDefaultAsync(cancellationToken);

            if (tag is null)
            {
                return(Result <IEnumerable <DishView> > .Fail <IEnumerable <DishView> >(ExceptionConstants.TAG_WAS_NOT_FOUND));
            }
            var dishTags = await _context.DishTags.Where(_ => _.TagId == tag.Id).AsNoTracking().ToListAsync(cancellationToken);

            if (!dishTags.Any())
            {
                return(Result <IEnumerable <DishView> > .Fail <IEnumerable <DishView> >(ExceptionConstants.DISHES_WERE_NOT_FOUND));
            }

            List <DishView> views = new List <DishView>();

            foreach (var dishTag in dishTags)
            {
                DishDB dish = await _context.Dishes.Where(_ => _.Id == dishTag.DishId).Include(c => c.DishTags).ThenInclude(sc => sc.Tag).Select(_ => _).AsNoTracking().FirstOrDefaultAsync(cancellationToken);

                DishView viewItem = _mapper.Map <DishView>(dish);
                viewItem.TotalCost = Math.Round(viewItem.Price * (1 - viewItem.Sale / 100), 2);
                viewItem.TagList   = new HashSet <TagToAdd>();
                foreach (var item in dish.DishTags)
                {
                    var tagItem = await _context.Tags.Where(_ => _.Id == item.TagId).AsNoTracking().FirstOrDefaultAsync(cancellationToken);

                    viewItem.TagList.Add(_mapper.Map <TagToAdd>(tagItem));
                }
                views.Add(viewItem);
            }

            return(Result <IEnumerable <DishView> > .Ok(_mapper.Map <IEnumerable <DishView> >(views)));
        }
示例#5
0
        public async Task <Result <TagDB> > AddTagDBAsync(TagToAdd tag, CancellationToken cancellationToken = default)
        {
            var tagToAdd = _mapper.Map <TagDB>(tag);

            _context.Tags.Add(tagToAdd);

            try
            {
                await _context.SaveChangesAsync(cancellationToken);

                TagDB tagAfterAdding = await _context.Tags.Where(_ => _.TagName == tagToAdd.TagName).Select(_ => _).AsNoTracking().FirstOrDefaultAsync(cancellationToken);

                return(Result <TagDB> .Ok(tagAfterAdding));
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Result <TagDB> .Fail <TagDB>(ExceptionConstants.CANNOT_SAVE_MODEL + ex.Message));
            }
            catch (DbUpdateException ex)
            {
                return(Result <TagDB> .Fail <TagDB>(ExceptionConstants.CANNOT_SAVE_MODEL + ex.Message));
            }
            catch (ArgumentNullException ex)
            {
                return(Result <TagDB> .Fail <TagDB>(ExceptionConstants.SOURCE_IS_NULL + ex.Message));
            }
        }
示例#6
0
 public static bool Delete(Tag myTag)
 {
     if (myTag != null)
     {
         return(TagDB.Delete(myTag.id));
     }
     else
     {
         return(false);
     }
 }
示例#7
0
        public async void Menu_GetByTagIndexAsync_PositiveAndNegative_Test()
        {
            var options = new DbContextOptionsBuilder <DreamFoodDeliveryContext>()
                          .UseInMemoryDatabase(databaseName: "Menu_GetByTagIndexAsync_PositiveAndNegative_Test")
                          .Options;
            string tagTestName       = "new";
            string tagTestSecondName = "old";

            using (var context = new DreamFoodDeliveryContext(options))
            {
                TagDB[] tags = new TagDB[]
                {
                    new TagDB
                    {
                        TagName = tagTestName
                    },
                    new TagDB
                    {
                        TagName = tagTestSecondName
                    },
                };
                DishDB dish = new DishDB
                {
                    Name = "dish"
                };

                context.AddRange(tags);
                context.Add(dish);
                DishTagDB dishTag = new DishTagDB
                {
                    TagId  = tags.FirstOrDefault(x => x.TagName == tagTestName).Id,
                    DishId = dish.Id
                };
                context.Add(dishTag);

                await context.SaveChangesAsync();
            }

            using (var context = new DreamFoodDeliveryContext(options))
            {
                var service = new MenuService(_mapper, context);

                var resultPositive = await service.GetByTagIndexAsync(tagTestName);

                var resultNegative = await service.GetByTagIndexAsync(tagTestSecondName);

                resultPositive.IsSuccess.Should().BeTrue();
                resultNegative.IsSuccess.Should().BeFalse();
            }
        }
        private GUTag LoadRootTag()
        {
            GUTag rootTag;

            if (MyCanvasType == LayoutCanvas.MAIN_CANVAS)
            {
                rootTag = TagDB.GetTag(Guid.Parse(DynamicCfg.Ins.MainCanvasRoot));
            }
            else
            {
                rootTag = TagDB.GetTag(Guid.Parse(DynamicCfg.Ins.SubCanvasRoot));
            }

            return(rootTag);
        }
示例#9
0
        public async Task <int> AddTag(Models.Tag tag)
        {
            var project = await _databaseContext.Projects.FindAsync(tag.Project.Id);

            var dbTag = new TagDB()
            {
                Project = project,
                Tasks   = new List <ProjectTaskDB>(),
                Text    = tag.Text
            };
            await _databaseContext.Tags.AddAsync(dbTag);

            await _databaseContext.SaveChangesAsync();

            return(dbTag.Id);
        }
示例#10
0
        // Loads the templateCreator, adds all of the tags to the tag combo box from the db.
        private void templateCreator_Load(object sender, EventArgs e)
        {
            //this.MinimumSize = new Size(this.Width, this.Height);
            //this.MaximumSize = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);

            //this.AutoSize = true;
            //this.AutoSizeMode = AutoSizeMode.GrowAndShrink;

            templateSelectorComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
            customTagComboBox.DropDownStyle        = ComboBoxStyle.DropDownList;

            TemplateDB.Load(ref templates);
            TagDB.Load(ref tags);

            foreach (Tag myTag in tags)
            {
                customTagComboBox.Items.Add(myTag.Name);
            }

            reloadTemplateList();
        }
示例#11
0
        public async Task <Result <TagToUpdate> > UpdateAsync(TagToUpdate tag, CancellationToken cancellationToken = default)
        {
            TagDB tagForUpdate = _mapper.Map <TagDB>(tag);

            tagForUpdate.Id = Guid.Parse(tag.Id);
            _context.Entry(tagForUpdate).Property(c => c.TagName).IsModified = true;

            try
            {
                await _context.SaveChangesAsync(cancellationToken);

                return(Result <TagToUpdate> .Ok(tag));
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Result <TagToUpdate> .Fail <TagToUpdate>(ExceptionConstants.CANNOT_UPDATE_MODEL + ex.Message));
            }
            catch (DbUpdateException ex)
            {
                return(Result <TagToUpdate> .Fail <TagToUpdate>(ExceptionConstants.CANNOT_UPDATE_MODEL + ex.Message));
            }
        }
示例#12
0
        // Prompts the user for a tag name, then inserts the tag into the RTB.
        // If the tag is blank, it closes out.
        // If the tag already exists, warns user to select from the drop down.
        private void customTagButton_Click(object sender, EventArgs e)
        {
            string input = Interaction.InputBox("Please enter the name of the tag you would like to create: ", "New Tag", "").ToLower();

            // If the custom tag box doesn't contain the tag and the input isn't blank, it will create a new tag and insert it into the DB.
            if (!customTagComboBox.Items.Contains(input) && input != "")
            {
                Tag myTag = new Tag
                {
                    Name = input
                };
                TagDB.Add(myTag);
                customTagComboBox.Items.Add(input);
                templateRichTextBox.SelectedText = "{$" + input + "}";
            }

            // If the combo box contains the tag, it will alert the user and insert the tag into the text box.
            else if (customTagComboBox.Items.Contains(input))
            {
                MessageBox.Show("Custom Tag already exists, inserting into the RichTextBox.", "attention");
                templateRichTextBox.SelectedText = "{$" + input + "}";
            }
        }
示例#13
0
        /// <summary>
        /// Returns the total number of entries for the specified tag id
        /// </summary>
        /// <param name="id">
        /// the id of the tag for which to retrieve the count
        /// </param>
        /// <returns>
        /// Returns the total number of entries for the specified tag id
        /// </returns>

        public static int CountByTag(long id)
        {
            return(TagDB.CountByTag(id));
        }
示例#14
0
 public TagLogic()
 {
     productDB = new ProductDB();
     tagDB     = new TagDB();
 }
        public async Task <Result <IEnumerable <DishView> > > GetAllDishesByRequestAsync(RequestParameters request, CancellationToken cancellationToken = default)
        {
            try
            {
                List <DishDB> dishesList = new List <DishDB>();
                if (request.TagsNames.Any())
                {
                    HashSet <DishTagDB> dishTagsList = new HashSet <DishTagDB>();
                    foreach (var tagName in request.TagsNames)
                    {
                        TagDB tag = await _context.Tags.Where(_ => _.TagName == tagName).Select(_ => _).AsNoTracking().FirstOrDefaultAsync(cancellationToken);

                        if (!(tag is null))
                        {
                            var dishTags = await _context.DishTags.Where(_ => _.TagId == tag.Id).AsNoTracking().ToListAsync(cancellationToken);

                            if (dishTags.Any())
                            {
                                foreach (var dishTag in dishTags)
                                {
                                    if (dishTagsList.Count is 0)
                                    {
                                        dishTagsList.Add(dishTag);
                                    }
                                    var dishTagToCompare = dishTagsList.Where(_ => _.DishId == dishTag.DishId).FirstOrDefault();
                                    if (!dishTagsList.Where(_ => _.DishId == dishTag.DishId).Any())
                                    {
                                        dishTagsList.Add(dishTag);
                                    }
                                }
                            }
                        }
                    }
                    if (!dishTagsList.Any())
                    {
                        return(Result <IEnumerable <DishView> > .Fail <IEnumerable <DishView> >(ExceptionConstants.DISHES_WERE_NOT_FOUND));
                    }
                    foreach (DishTagDB dishTag in dishTagsList)
                    {
                        DishDB dish = await _context.Dishes.Where(_ => _.Id == dishTag.DishId).Include(c => c.DishTags).ThenInclude(sc => sc.Tag).Select(_ => _).AsNoTracking().FirstOrDefaultAsync(cancellationToken);

                        dishesList.Add(dish);
                    }
                }
                else
                {
                    dishesList = await _context.Dishes.Include(c => c.DishTags).ThenInclude(sc => sc.Tag).AsNoTracking().ToListAsync(cancellationToken);
                }

                if (!dishesList.Any())
                {
                    return(Result <IEnumerable <DishView> > .Fail <IEnumerable <DishView> >(ExceptionConstants.DISHES_WERE_NOT_FOUND));
                }
                if (!string.IsNullOrEmpty(request.Request) && dishesList.Any())
                {
                    dishesList = dishesList.Where(_ => _.Name.Contains(request.Request) || _.Composition.Contains(request.Request) || _.Description.Contains(request.Request)).ToList();
                }
                if (request.OnSale && dishesList.Any())
                {
                    dishesList = dishesList.Where(_ => _.Sale > 0).ToList();
                }
                if (request.LowerPrice > 0 && dishesList.Any())
                {
                    dishesList = dishesList.Where(_ => _.Price >= request.LowerPrice).ToList();
                }
                if (request.UpperPrice > 0 && request.UpperPrice >= request.LowerPrice && dishesList.Any())
                {
                    dishesList = dishesList.Where(_ => _.Price <= request.UpperPrice).ToList();
                }

                List <DishView> views = await CollectViews(dishesList);

                return(Result <IEnumerable <DishView> > .Ok(_mapper.Map <IEnumerable <DishView> >(views)));
            }
            catch (ArgumentNullException ex)
            {
                return(Result <IEnumerable <DishView> > .Fail <IEnumerable <DishView> >(ExceptionConstants.SOURCE_IS_NULL + ex.Message));
            }
        }
示例#16
0
 public void SetUp()
 {
     tagDB = new TagDB(connectionString);
 }
示例#17
0
 public static Tag GetItem(long id)
 {
     return(TagDB.GetItem(id));
 }
示例#18
0
 public static long Save(Tag myTag)
 {
     return(TagDB.Save(myTag));
 }
示例#19
0
 public static List <Tag> GetListUsedTags()
 {
     return(TagDB.GetListUsedTags());
 }
示例#20
0
 public static List <Tag> GetList(int StartRow, int PageSize)
 {
     return(TagDB.GetList(StartRow, PageSize));
 }
示例#21
0
 public static List <Tag> GetList()
 {
     return(TagDB.GetList());
 }
示例#22
0
        /// <summary>
        /// Returns the total number of tags in the database
        /// </summary>
        /// <param name="StartRow">
        /// The start position in the result set to retrieve records from
        /// </param>
        /// <param name="PageSize">
        /// The maximum number of records to retrieve from position StartRow
        /// </param>
        /// <returns>
        /// Returns the total number of tags in the database
        /// </returns>

        public static int Count(int StartRow, int PageSize)
        {
            return(TagDB.Count(StartRow, PageSize));
        }