示例#1
0
        //----------------------------------------------------------


        //----------------------------------------------------------
        //Метод по добавлению нового товара и по сохранению изменений в существующих
        public void SaveProduct(Cosmetic obj)
        {
            if (obj.ProductId == 0)
            {
                context.Cosmetics.Add(obj);
            }

            else
            {
                Cosmetic prod = context.Cosmetics.Find(obj.ProductId);
                if (prod != null)
                {
                    prod.ProductName = obj.ProductName;
                    prod.CategoryId  = obj.CategoryId;
                    prod.NewPrice    = obj.NewPrice;
                    prod.Description = obj.Description;
                    prod.Type        = obj.Type;
                    prod.SubType     = obj.SubType;
                    if (obj.ImageMimeType != null && obj.ImageData != null)
                    {
                        prod.ImageData     = obj.ImageData;
                        prod.ImageMimeType = obj.ImageMimeType;
                    }
                }
            }
            context.SaveChanges();
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cosmetic"></param>
        /// <returns></returns>
        public bool addNewCosmetic(Cosmetic cosmetic)
        {
            var checkExists = Master_Data_DB.Cosmetics.Where(cos =>

                                                             cos.Name == cosmetic.Name && cos.Category == cosmetic.Category

                                                             ).ToList();


            if (checkExists.Count() == 0)
            {
                if (Master_Data_DB.Cosmetics.Add(cosmetic) != null)
                {
                    Master_Data_DB.SaveChanges();
                    return(true);
                }
            }
            // if exists but deleted, create new product too
            else if (checkExists[0].Status == -1)
            {
                if (Master_Data_DB.Cosmetics.Add(cosmetic) != null)
                {
                    Master_Data_DB.SaveChanges();
                    return(true);
                }
            }

            return(false);
        }
示例#3
0
        public async Task <IActionResult> PutCosmetic(int id, Cosmetic cosmetic)
        {
            if (id != cosmetic.Id)
            {
                return(BadRequest());
            }

            CosmeticValid valid = new CosmeticValid(_context, cosmetic);

            if (valid.Valid() == false)
            {
                return(BadRequest("Данное косметичсекое средство уже существует"));
            }

            _context.Entry(cosmetic).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CosmeticExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#4
0
 private Cosmetic CreateModel(CosmeticBindingModel model, Cosmetic cosmetic)
 {
     cosmetic.CosmeticName = model.CosmeticName;
     cosmetic.Price        = model.Price;
     cosmetic.EmployeeId   = (int)model.EmployeeId;
     return(cosmetic);
 }
示例#5
0
        //-----------------------------------------------------------
        //Выбираем продукт по идшнику
        public Cosmetic GetProductById(int ProductId)
        {
            Cosmetic obj = context.Cosmetics.FirstOrDefault(product => product.ProductId == ProductId);

            obj.Colors = colorRepo.GetAllColorsFromBase(obj.ProductId, obj.CategoryId).ToList();
            return(obj);
        }
示例#6
0
        //-----------------------------------------------------
        //Редактирование косметики
        public ActionResult EditCosmetic(int ProductId)
        {
            Cosmetic          cosmetic = cosmeticrepo.GetProductById(ProductId);
            CosmeticViewModel obj      = Mapper.Map <CosmeticViewModel>(cosmetic);

            return(View(obj));
        }
示例#7
0
        //------------------------------------------------------
        //Удаление товара
        public ActionResult DeleteProduct(int ProductId, int CategoryId)
        {
            if (CategoryId == 1)
            {
                Parfum obj = productrepo.GetProductById(ProductId);
                productrepo.DeleteProduct(obj);
                TempData["message"] = String.Format("Товар '{0}' удален из базы", obj.ProductName);
                return(RedirectToAction("ShowProductsInCategory", "Admin", new { obj.CategoryId }));
            }

            else if (CategoryId == 2)
            {
                Cosmetic obj = cosmeticrepo.GetProductById(ProductId);
                cosmeticrepo.DeleteProduct(obj);
                TempData["message"] = String.Format("Товар '{0}' удален из базы", obj.ProductName);
                return(RedirectToAction("ShowProductsInCategory", "Admin", new { obj.CategoryId }));
            }

            else if (CategoryId == 3)
            {
                Care obj = carerepo.GetProductById(ProductId);
                carerepo.DeleteProduct(obj);
                TempData["message"] = String.Format("Товар'{0}'удвлен из базы", obj.ProductName);
                return(RedirectToAction("ShowProductsInCategory", "Admin", new { obj.CategoryId }));
            }

            return(View());
        }
示例#8
0
        public bool updateCosmetic(Cosmetic cosmetic)
        {
            var cos = Master_Data_DB.Cosmetics.Find(cosmetic.ID);

            var checkExists = Master_Data_DB.Cosmetics.Where(cosm =>

                                                             cosm.Name == cosmetic.Name && cosm.Category == cosmetic.Category && cosm.ID != cosmetic.ID

                                                             ).ToList();

            if (cos != null && checkExists.Count() == 0)
            {
                cos.Name     = cosmetic.Name;
                cos.Image    = cosmetic.Image;
                cos.Category = cosmetic.Category;
                cos.Price    = cosmetic.Price;
                cos.Detail   = cosmetic.Detail;
                cos.Origin   = cosmetic.Origin;
                Master_Data_DB.SaveChanges();

                return(true);
            }

            return(false);
        }
示例#9
0
        public void TestMethod3()
        {
            decimal expectedTotalPrice = decimal.Round((decimal)74.68, 2, MidpointRounding.AwayFromZero);
            decimal expectedTotalTaxes = decimal.Round((decimal)6.70, 2, MidpointRounding.AwayFromZero);

            Console.WriteLine("Input3:");
            Cosmetic c1 = new Cosmetic("bottle of perfume", 1, (decimal)27.99, true);
            Cosmetic c2 = new Cosmetic("bottle of perfume", 1, (decimal)18.99, false);
            Drug     d  = new Drug("packet of headache pills", 1, (decimal)9.75, false);
            Food     f  = new Food("box of chocolates", 1, (decimal)11.25, true);

            Console.WriteLine(c1.ToStringWithoutTaxes());
            Console.WriteLine(c2.ToStringWithoutTaxes());
            Console.WriteLine(d.ToStringWithoutTaxes());
            Console.WriteLine(f.ToStringWithoutTaxes());
            Console.WriteLine("Output1:");
            Console.WriteLine(c1.ToString());
            Console.WriteLine(c2.ToString());
            Console.WriteLine(d.ToString());
            Console.WriteLine(f.ToString());
            decimal totalTaxes = c1.GetTotalTaxes() + c2.GetTotalTaxes() + d.GetTotalTaxes() + f.GetTotalTaxes();
            decimal totalPrice = c1.GetTotalPrice() + c2.GetTotalPrice() + d.GetTotalPrice() + f.GetTotalPrice();

            Console.WriteLine("Sales Taxes: " + totalTaxes);
            Console.WriteLine("Total: " + totalPrice);
            Assert.AreEqual(totalTaxes, expectedTotalTaxes);
            Assert.AreEqual(totalPrice, expectedTotalPrice);
        }
示例#10
0
        public async Task <IActionResult> Edit(Cosmetic cosmetic)
        {
            db.Cosmetics.Update(cosmetic);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public IActionResult Add(AddCosmeticViewModel addCosmeticVM)
        {
            if (ModelState.IsValid)// && addCheeseViewModel.CategoryID != 0)
            {
                //if (addCosmeticVM.ColorID != 0 && addCosmeticVM.FormulationID != 0 && addCosmeticVM.FinishID != 0 && addCosmeticVM.RatingID != 0 && addCosmeticVM.SkinTypeID != 0)
                //{
                Cosmetic newCosmetic = new Cosmetic
                {
                    //fish for all these ids in database
                    Name        = addCosmeticVM.Name,
                    Description = addCosmeticVM.Description,
                    Color       = context.Colors.Single(c => c.ID == addCosmeticVM.ColorID),
                    Finish      = context.Finishs.Single(f => f.ID == addCosmeticVM.FinishID),
                    Formulation = context.Formulations.Single(f => f.ID == addCosmeticVM.FormulationID),
                    Rating      = context.Ratings.Single(r => r.ID == addCosmeticVM.RatingID),
                    SkinType    = context.SkinTypes.Single(s => s.ID == addCosmeticVM.SkinTypeID)
                };

                context.Cosmetics.Add(newCosmetic);
                context.SaveChanges();

                return(Redirect("/Cosmetic"));
                //  }
            }

            return(View(addCosmeticVM));
        }
        public async Task <IActionResult> PutCosmetic(int id, Cosmetic cosmetic)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (id != cosmetic.CosmeticId)
            {
                return(BadRequest());
            }

            _context.Entry(cosmetic).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CosmeticExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#13
0
        public ProductDetailScreen(Cosmetic data)
        {
            InitializeComponent();

            Cosmetic product = data;

            productFullDetail.DataContext = data;
        }
示例#14
0
 public void AddCosmetic(Cosmetic cosmetic)
 {
     if (cosmetic == null)
     {
         return;
     }
     cosmetics.Add(cosmetic);
 }
示例#15
0
        private void SelectProductDelete_Click(object sender, RoutedEventArgs e)
        {
            productFullDetail.Visibility = Visibility.Visible;
            deleteForm.Visibility        = Visibility.Collapsed;
            Cosmetic cosmetic = (Cosmetic)cbCosmeticDel.SelectedItem;

            productFullDetail.DataContext = cosmetic;
        }
示例#16
0
        private void AddProductFrmAdd_Click(object sender, RoutedEventArgs e)
        {
            int price;

            if (string.IsNullOrEmpty(txtProductName.Text) || string.IsNullOrEmpty(txtProductPrice.Text) || string.IsNullOrEmpty(txtProductOrgin.Text) || string.IsNullOrEmpty(txtProductDetail.Text))
            {
                MessageBox.Show("Vui lòng nhập đầy đủ thông tin!", "Lỗi");
                return;
            }

            if (!int.TryParse(txtProductPrice.Text, out price))
            {
                MessageBox.Show("Giá của sản phẩm không hợp lệ!", "Lỗi");
                return;
            }

            int      categoryId = ((Category)cbCatogoryFrmAdd.SelectedItem).ID;
            Cosmetic cosmetic   = new Cosmetic
            {
                Category = categoryId,
                Name     = txtProductName.Text,
                Price    = price,
                Origin   = txtProductOrgin.Text,
                Detail   = txtProductDetail.Text
            };

            string iconFullName = "";
            string sourcePath   = "";

            if (Global.isUsingtheOldFile(reviewIcon.Source.ToString(), cosmetic.Image))
            {
                iconFullName = cosmetic.Image;//default image
            }
            else
            {
                initNewImageProduct(reviewIcon.Source.ToString(), cosmetic.Name, out sourcePath, out iconFullName);
                cosmetic.Image = iconFullName;//update new image
            }
            //Lấy thư mục chứa file icon của app
            string iconFolder = Global.getBaseFolder() + @"\Images\cosmetic\";

            bool result = masterDataManager.addNewCosmetic(cosmetic);

            if (result)
            {
                //cosmetic.row_in_db = result;
                MessageBox.Show($"Thêm {cosmetic.Name} thành công", "Thành công");
                if (!cosmetic.Image.Equals("default_cosmetic_icon.ico"))
                {
                    Global.copyFileTo(sourcePath, iconFolder + iconFullName);
                }
                refreshFormAddProduct();
            }
            else
            {
                MessageBox.Show($"Không thể thêm {cosmetic.Name}. Vui lòng thử lại", "Lỗi");
            }
        }
示例#17
0
        //-----------------------------------------
        //Добавление просмотра
        public void AddCountOfView(int productId)
        {
            Cosmetic obj = GetProductById(productId);

            foreach (var item in obj.Colors)
            {
                context.Entry(item).State = EntityState.Modified;
            }
            obj.CountOfView += 1;
            context.SaveChanges();
        }
示例#18
0
        //-----------------------------------------
        //Изменение доступности товара
        public void ChangeAvailability(int productId, bool isAvailable)
        {
            Cosmetic obj = GetProductById(productId);

            foreach (var item in obj.Colors)
            {
                context.Entry(item).State = EntityState.Modified;
            }
            obj.IsAvailable = isAvailable;
            context.SaveChanges();
        }
示例#19
0
 public void OpenWindow(int _siblingIndex, Cosmetic _lockedCosmetic)
 {
     Reset();
     lockedCosmeticName        = _lockedCosmetic.name;
     siblingIndex              = _siblingIndex;
     cosmeticImage.sprite      = _lockedCosmetic.unlockedSprite;
     cosmeticDescription.text  = _lockedCosmetic.description;
     amountOfDiamondsText.text = _lockedCosmetic.amountOfDiamonsNeeded.ToString();
     darkBackground.SetActive(true);
     gameObject.SetActive(true);
 }
        public async Task <ActionResult <Cosmetic> > PostCosmetic(Cosmetic cosmetic)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            _context.Cosmetic.Add(cosmetic);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCosmetic", new { id = cosmetic.CosmeticId }, cosmetic));
        }
示例#21
0
        public async Task <IActionResult> ConfirmDelete(int?id)
        {
            if (id != null)
            {
                Cosmetic cosmetic = await db.Cosmetics.FirstOrDefaultAsync(p => p.Id == id);

                if (cosmetic != null)
                {
                    return(View(cosmetic));
                }
            }
            return(NotFound());
        }
示例#22
0
    public void DisplayWindow()
    {
        GameManager.isPausing = true;

        Cosmetic_Previewer.singleton.Reset();

        gameObject.SetActive(true);

        for (int i = 0; i < cosmeticsParent.childCount; i++)
        {
            Cosmetic _cosmetic = cosmeticsParent.GetChild(i).GetComponent <Cosmetic>();
            _cosmetic.Reset();
        }
    }
示例#23
0
        public async Task <ActionResult <Cosmetic> > PostCosmetic(Cosmetic cosmetic)
        {
            CosmeticValid valid = new CosmeticValid(_context, cosmetic);

            if (valid.Valid() == false)
            {
                return(BadRequest("Данное косметичсекое средство уже существует"));
            }

            _context.Cosmetics.Add(cosmetic);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCosmetic", new { id = cosmetic.Id }, cosmetic));
        }
示例#24
0
    //[SerializeField] Cosmet cosmeticPreviewer;

    // Use this for initialization
    public void StartSettings()
    {
        // Sets current player sprite
        int      _currentCosmeticIndex = PlayerPrefs.GetInt("currentCosmeticChildNr");
        Cosmetic _cosmetic             = cosmeticsParent.GetChild(_currentCosmeticIndex).GetComponent <Cosmetic>();
        Sprite   _sprite = _cosmetic.unlockedSprite;

        GameManager.currentPlayer.spriteRenderer.sprite = _sprite;
        exclamationPoint.SetActive(false);
        //guiMessenger.gameObject.SetActive(false);
        gameObject.SetActive(false);


        //Cosmetic_Previewer.StartSettings();
    }
示例#25
0
    public void HandleClick()
    {
        Cosmetic cosmetic = _handler.cosmeticDefinition[pizzaIndex];

        if (_handler.unlocked[pizzaIndex])
        {
            _handler.SwitchSkin(pizzaIndex);
        }
        else
        {
            _handler.buyMenu.name = $"Buy menu{pizzaIndex}";
            _handler.buyMenu.SetActive(true);
            _handler.buyMenu.GetComponentInChildren <Text>().text = $"Unlock this skin?\n\nDo you wish to purchase\nthis skin for {cosmetic.cost} coins?";
        }
    }
示例#26
0
        public async Task <IActionResult> Delete(int?id)
        {
            if (id != null)
            {
                Cosmetic cosmetic = await db.Cosmetics.FirstOrDefaultAsync(p => p.Id == id);

                if (cosmetic != null)
                {
                    db.Cosmetics.Remove(cosmetic);
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
            }
            return(NotFound());
        }
示例#27
0
 public void Delete(CosmeticBindingModel model)
 {
     using (var context = new BeautySaloonDatabase())
     {
         Cosmetic element = context.Cosmetics.FirstOrDefault(rec => rec.Id == model.Id);
         if (element != null)
         {
             context.Cosmetics.Remove(element);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Элемент не найден");
         }
     }
 }
示例#28
0
        public FileContentResult GetImage(int ProductId, int CategoryId)
        {
            if (CategoryId == 1)
            {
                Parfum obj = productrepo.GetProductById(ProductId);
                if (obj != null)
                {
                    return(File(obj.ImageData, obj.ImageMimeType));
                }

                else
                {
                    return(null);
                }
            }

            else if (CategoryId == 2)
            {
                Cosmetic obj = cosmeticrepo.GetProductById(ProductId);
                if (obj != null)
                {
                    return(File(obj.ImageData, obj.ImageMimeType));
                }

                else
                {
                    return(null);
                }
            }

            else if (CategoryId == 3)
            {
                Care obj = carerepo.GetProductById(ProductId);
                if (obj != null)
                {
                    return(File(obj.ImageData, obj.ImageMimeType));
                }

                else
                {
                    return(null);
                }
            }

            return(null);
        }
示例#29
0
    private void Start()
    {
        for (int index = 0; index < cosmeticDefinition.Count; index++)
        {
            Cosmetic   cosmectic      = cosmeticDefinition[index];
            GameObject cosmeticObject = Instantiate(cosmeticPrefab, grid.transform, true);

            cosmeticObject.transform.localScale = new Vector3(1, 1, 1);

            cosmeticObject.name = $"Pizza:{index}";

            Image image = cosmeticObject.GetComponent <Image>();
            image.sprite = cosmectic.sprite;

            cosmeticObject.GetComponent <CosmeticData>().pizzaIndex = index;
        }
    }
示例#30
0
        private void DeleteProductSelected_Click(object sender, RoutedEventArgs e)
        {
            Cosmetic cosmetic = productFullDetail.DataContext as Cosmetic;
            bool     result   = masterDataManager.deleteCosmetic(cosmetic.ID);

            if (result)
            {
                MessageBox.Show($"Đã xóa {cosmetic.Name}", "Thành công");
                if (!cosmetic.Image.Equals("default_cosmetic_icon.ico"))
                {
                    Global.deleteFile($"{Global.getBaseFolder()}\\Images\\cosmetic\\{cosmetic.Image}");
                }
                BtnBack_Click(null, null);
            }
            else
            {
                MessageBox.Show($"Xóa {cosmetic.Name} không thành công", "Lỗi");
            }
        }