//---------------------------------------------------------- //---------------------------------------------------------- //Метод по добавлению нового товара и по сохранению изменений в существующих 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(); }
/// <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); }
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()); }
private Cosmetic CreateModel(CosmeticBindingModel model, Cosmetic cosmetic) { cosmetic.CosmeticName = model.CosmeticName; cosmetic.Price = model.Price; cosmetic.EmployeeId = (int)model.EmployeeId; return(cosmetic); }
//----------------------------------------------------------- //Выбираем продукт по идшнику 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); }
//----------------------------------------------------- //Редактирование косметики public ActionResult EditCosmetic(int ProductId) { Cosmetic cosmetic = cosmeticrepo.GetProductById(ProductId); CosmeticViewModel obj = Mapper.Map <CosmeticViewModel>(cosmetic); return(View(obj)); }
//------------------------------------------------------ //Удаление товара 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()); }
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); }
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); }
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()); }
public ProductDetailScreen(Cosmetic data) { InitializeComponent(); Cosmetic product = data; productFullDetail.DataContext = data; }
public void AddCosmetic(Cosmetic cosmetic) { if (cosmetic == null) { return; } cosmetics.Add(cosmetic); }
private void SelectProductDelete_Click(object sender, RoutedEventArgs e) { productFullDetail.Visibility = Visibility.Visible; deleteForm.Visibility = Visibility.Collapsed; Cosmetic cosmetic = (Cosmetic)cbCosmeticDel.SelectedItem; productFullDetail.DataContext = cosmetic; }
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"); } }
//----------------------------------------- //Добавление просмотра 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(); }
//----------------------------------------- //Изменение доступности товара 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(); }
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)); }
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()); }
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(); } }
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)); }
//[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(); }
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?"; } }
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()); }
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("Элемент не найден"); } } }
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); }
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; } }
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"); } }