private void SkuGenerator() { var tempGuid = Guid.NewGuid().ToString(); var sku = $"{ProductName.Substring(0, 3)}-{CategoryName.Substring(0, 3)}-{tempGuid.Substring(tempGuid.Length - 6)}"; Sku = sku; }
/// <summary> /// The OnAdd /// </summary> private async void OnAdd() { await ValidateAsync(); if (HasErrors) { return; } var codeNumber = _context.Products.Select(c => c.CodeNumber).OrderByDescending(c => c).FirstOrDefault(); int finalNumber = 0; if (codeNumber > 0) { finalNumber = codeNumber + 1; } else { finalNumber = 1000001; } string codeString = ProductName.Substring(0, 4).ToUpper(); //var picture = ImageToByteArray(Picture); Product newProduct = new Product() { CodeNumber = finalNumber, CodeString = codeString, Name = ProductName, Description = Description, Type = SelectedType, Stock = Int32.Parse(Stock), Price = Double.Parse(Price), Image = Picture }; _context.Products.Add(newProduct); _context.SaveChanges(); MessengerInstance.Send(new RefreshMessage()); OnClose(); }