示例#1
0
        public static int ValidationSizeByGender(int size, GenderCategory category)
        {
            if (category == GenderCategory.man)
            {
                while (size < 40 || size > 49)
                {
                    Console.Write("Incorrect! Size should be from 40 to 49");
                    string input = Console.ReadLine();
                    size = ValidationInput(input);
                }
            }

            else if (category == GenderCategory.woman)
            {
                while (size < 35 || size > 39)
                {
                    Console.Write("Incorrect! Size should be from 35 to 39");
                    string input = Console.ReadLine();
                    size = ValidationInput(input);
                }
            }

            else if (category == GenderCategory.kids)
            {
                while (size < 18 || size > 34)
                {
                    Console.Write("Incorrect! Size should be from 18 to 34");
                    string input = Console.ReadLine();
                    size = ValidationInput(input);
                }
            }
            return(size);
        }
        public void EditGenderCategory(GenderCategory genderCategory)
        {
            var editedGenderCategory = _context.GenderCategory.First(x => x.ID == genderCategory.ID);

            editedGenderCategory.Name = genderCategory.Name;
            _context.Entry(editedGenderCategory).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            _context.SaveChanges();
        }
示例#3
0
 public Socks(int countSock, string brandOfSocks, GenderCategory category, int size, string color, string material)
 {
     CountSock    = countSock;
     IdNumber     = rndId.Next(1, 1000);
     BrandOfSocks = brandOfSocks;
     Category     = category;
     Size         = size;
     Color        = color;
     Material     = material;
 }
示例#4
0
        public async Task <GenderCategory> UpdateGenderCategoryAsync(GenderCategory category, string userId)
        {
            var existing = await GetGenderCategoryAsync(category.Id, userId);//this is more for cheking that category is for this user

            if (existing != null)
            {
                existing.Name = category.Name;
                _context.Update(existing);
                await _context.SaveChangesAsync();
            }
            return(existing);
        }
 public IActionResult Update([FromBody] GenderCategory genderCategory)
 {
     try
     {
         _genderCategoryService.EditGenderCategory(genderCategory);
         return(Ok());
     }
     catch (Exception)
     {
         return(BadRequest("Gender not found"));
     }
 }
 public IActionResult Create(GenderCategory genderCategory)
 {
     try
     {
         var newGender = _genderCategoryService.AddGenderCategory(genderCategory);
         return(CreatedAtRoute("GetGenderById", new { id = newGender.ID }, newGender));
     }
     catch (Exception)
     {
         return(BadRequest("Value is null"));
     }
 }
 public async Task<IActionResult> UpdateGenderCategory([FromBody] GenderCategory category)
 {
     try
     {
         var userId = User.Identity.Name;
         category = await _organizerService.UpdateGenderCategoryAsync(category, userId);
         return Ok(category);
     }
     catch (Exception ex)
     {
         return BadRequest(ex.Message);
     }
 }
示例#8
0
        private async Task EnsureGenderCategoriesExistAsync(int categoryId, string categoryName)
        {
            var category = await _context.GenderCaegories.FirstOrDefaultAsync(gc => gc.Name == categoryName);

            if (category == null)
            {
                category = new GenderCategory()
                {
                    Id = categoryId, Name = categoryName
                };
                _context.Add(category);
                await _context.SaveChangesAsync();
            }
        }
示例#9
0
        public async Task <GenderCategory> AddGenderCategoryAsync(GenderCategory genderCategory, string userId)
        {
            var group = await _context
                        .GenderCategoryGroups
                        .FirstOrDefaultAsync(acg => acg.ApplicationUserId == userId && acg.Id == genderCategory.GenderCategoryGroupId);

            if (group != null)
            {
                _context.Add(genderCategory);
                await _context.SaveChangesAsync();

                return(genderCategory);
            }
            throw new Exception("Could not add a category");//this should never happen
        }
 public GenderCategory AddGenderCategory(GenderCategory genderCategory)
 {
     _context.GenderCategory.Add(genderCategory);
     _context.SaveChanges();
     return(genderCategory);
 }
示例#11
0
        static void Main(string[] args)
        {
            int    numbOfProductValid;
            string numbOfProduct;
            string selectKey;
            string selectOption;
            int    countSock = 1;

            do
            {
                Console.Clear();

                Console.WriteLine($"Select the option:\npress \"1\" - Input information about socks\npress \"2\" - Show the list of all products\npress \"3\" - Show information about 1 product" +
                                  $"\npress \"4\" - Delete one product\npress \"5\" - Exit programm");

                selectOption = Console.ReadLine();

                switch (selectOption)
                {
                case "1":
                {
                    Console.WriteLine("Please, input information about socks :)\n");

                    Console.Write("1. Brand of socks:");
                    string brandOfSocks = Console.ReadLine();

                    Console.Write("2. Gender category: 1-man, 2-woman, 3-kids:");
                    string         genderString   = Console.ReadLine();
                    int            gender         = ValidationInputCategory(genderString);
                    GenderCategory genderCategory = (GenderCategory)gender;
                    Console.Write($"You selected category: " + genderCategory.ToString() + "\n");

                    Console.Write("3. Size:");
                    string sizeString          = Console.ReadLine();
                    int    size                = ValidationInput(sizeString);
                    int    sizeAfterValidation = ValidationSizeByGender(size, genderCategory);

                    Console.Write("4. Color:");
                    string color = Console.ReadLine();

                    Console.Write("5. Material:");
                    string material = Console.ReadLine();

                    Socks socks = new Socks(countSock, brandOfSocks, genderCategory, sizeAfterValidation, color, material);

                    ListOfSocks.addSocks(socks);

                    Console.WriteLine(socks.ToString());

                    countSock += 1;
                    break;
                }

                case "2":
                {
                    Console.Clear();

                    Console.WriteLine($"The list of all products:");
                    foreach (var item in ListOfSocks.listOfSocks)
                    {
                        Console.WriteLine(item.ToString());
                    }
                    break;
                }

                case "3":
                {
                    Console.WriteLine($"Enter the product number, for more details:");

                    numbOfProduct      = Console.ReadLine();
                    numbOfProductValid = ValidationInput(numbOfProduct);

                    for (int i = 0; i < ListOfSocks.listOfSocks.Count; i++)
                    {
                        if (ListOfSocks.listOfSocks[i].CountSock.Equals(numbOfProductValid))
                        {
                            Console.WriteLine(ListOfSocks.listOfSocks[i].ToString());
                        }
                    }
                    break;
                }

                case "4":
                {
                    Console.WriteLine($"\nEnter the product number to remove it from this list:");

                    foreach (var item in ListOfSocks.listOfSocks)
                    {
                        Console.WriteLine(item.ToString());
                    }

                    numbOfProduct      = Console.ReadLine();
                    numbOfProductValid = ValidationInput(numbOfProduct);

                    for (int i = 0; i < ListOfSocks.listOfSocks.Count; i++)
                    {
                        if (ListOfSocks.listOfSocks[i].CountSock.Equals(numbOfProductValid))
                        {
                            ListOfSocks.listOfSocks.RemoveAt(i);
                            i--;
                        }
                    }

                    foreach (var item in ListOfSocks.listOfSocks)
                    {
                        Console.WriteLine(item.ToString());
                    }

                    break;
                }

                case "5":
                {
                    return;
                }
                }

                Console.WriteLine("Do you want return to menu? - press \"y\"");
                selectKey = Console.ReadLine();
            }while (selectKey.Equals("y"));



            Console.ReadKey();
        }