public async Task <IActionResult> Create(ProductBrand productBrand, IFormFile limg) { if (ModelState.IsValid) { var bname = await _context.ProductBrand.FirstOrDefaultAsync(a => a.Name == productBrand.Name); if (bname == null) { if (limg != null == limg.Length > 0) { string brandimgPath = _env.WebRootPath + "/brands/"; string FileUniqueName = Guid.NewGuid().ToString() + Path.GetExtension(limg.FileName); await limg.CopyToAsync(new FileStream(brandimgPath + FileUniqueName, FileMode.CreateNew)); productBrand.Logo = FileUniqueName; } productBrand.Status = "Active"; productBrand.CreatedDate = DateTime.Now; _context.Add(productBrand); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } return(View(productBrand)); }
public async Task <IActionResult> Create(ProductCategory productCategory, IFormFile categoryimg) { try { if (ModelState.IsValid) { Boolean Cname = await _context.ProductCategory.AnyAsync(m => m.Name == productCategory.Name); if (!Cname) { if (categoryimg != null && categoryimg.Length > 0) { string categoryimgPath = _env.WebRootPath + "/categories/"; string FileUniqueName = Guid.NewGuid().ToString() + Path.GetExtension(categoryimg.FileName); await categoryimg.CopyToAsync(new FileStream(categoryimgPath + FileUniqueName, FileMode.CreateNew)); productCategory.Image = FileUniqueName; } productCategory.Status = "Active"; productCategory.CreatedDate = DateTime.Now; _context.Add(productCategory); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } return(View(productCategory)); } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> Create(ProductSale productSale) { if (ModelState.IsValid) { _context.Add(productSale); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(productSale)); }
public async Task <IActionResult> Create([Bind("Id,PurchaseDate,PurchasePrice,Discount,FinalPrice,Status,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy")] ProductPurchase productPurchase) { if (ModelState.IsValid) { _context.Add(productPurchase); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(productPurchase)); }
public async Task <IActionResult> Create(SystemUser systemUser, IFormFile user_pic) { if (ModelState.IsValid) { Boolean usr = _context.SystemUser.Any(user => user.Username == systemUser.Username); Boolean usrmail = _context.SystemUser.Any(user => user.Email == systemUser.Email); if (!usr && !usrmail) { if (user_pic != null) { string pic_name = Guid.NewGuid().ToString() + Path.GetExtension(user_pic.FileName); string pic_path = _env.WebRootPath.ToString() + "/WebData/SystemUsersImages/" + (pic_name); System.IO.FileStream FS = new System.IO.FileStream(pic_path, FileMode.Create); await user_pic.CopyToAsync(FS); systemUser.ProfilePicture = pic_name; } MailMessage mail = new MailMessage(); mail.From = new MailAddress("*****@*****.**", "TheetaPOS"); mail.To.Add(systemUser.Email); mail.Subject = "Welcome!" + systemUser.DisplayName + " You are Registered Successfully"; mail.Body = "<h3>Congratulations!</h3><br><p>You will be happy after using our Services</p>"; mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "rizwan67"); smtp.Port = 587; smtp.EnableSsl = true; smtp.Send(mail); systemUser.Role = "Staff"; _context.Add(systemUser); await _context.SaveChangesAsync(); ViewBag.SuccMsg = "Successfuly Registered"; return(RedirectToAction(nameof(Login))); } else { ViewBag.ErrMsg = "This " + systemUser.Username + " or " + systemUser.Email + " is Already Exist"; return(View(systemUser)); } } return(View(nameof(Create))); }
public async Task <IActionResult> Create(Product product, IList <IFormFile> pimg) { if (ModelState.IsValid) { var Pname = await _context.Product.FirstOrDefaultAsync(m => m.Name == product.Name); if (Pname == null) { if (pimg != null) { string productimgFPath = _env.WebRootPath + "/products/"; string Filepath = ""; foreach (var Images in pimg) { string filename = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(Images.FileName); Filepath = productimgFPath + filename; System.IO.FileStream fs = new System.IO.FileStream(Filepath, System.IO.FileMode.Create); Images.CopyTo(fs); product.Images += (filename + ","); } if (!string.IsNullOrEmpty(product.Images)) { product.Images = product.Images.Remove(product.Images.LastIndexOf(",")); } } product.Status = "Active"; product.CreatedDate = DateTime.Now; product.OpeningDate = DateTime.Now; _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } return(View(product)); }