//CREATE public IActionResult Create(User user) { if (ModelState.IsValid) { _context.Add(user); _context.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "RoleId,RoleName")] UserRole userRole) { if (ModelState.IsValid) { db.UserRoles.Add(userRole); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(userRole)); }
public ActionResult Create([Bind(Include = "Id,Name,Phone,Email")] Register register) { if (ModelState.IsValid) { db.Registers.Add(register); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(register)); }
public ActionResult Create(User user) { if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.RoleId = new SelectList(db.UserRoles, "RoleId", "RoleName", user.RoleId); return(View(user)); }
public ActionResult AddCat(Category category, HttpPostedFileBase file) { if (file != null) { using (MemoryStream ms = new MemoryStream()) { file.InputStream.CopyTo(ms); byte[] array = ms.GetBuffer(); category.Image = array; } } learn.Categories.Add(category); learn.SaveChanges(); return(RedirectToAction("Categories")); }
public ActionResult Create(FeedBacks feedBacks) { feedBacks.ModifieddBy = Notice.SystemAddmin; feedBacks.Creared = DateTime.Now; feedBacks.Modified = DateTime.Now; feedBacks.CreatedBy = Notice.SystemAddmin; if (ModelState.IsValid) { db.FeedBacks.Add(feedBacks); db.SaveChanges(); return(RedirectToAction(Notice.Index)); } return(View(feedBacks)); }
public ActionResult Create(Categories categories) { categories.ModifieddBy = Notice.SystemAddmin; categories.CreatedBy = Notice.SystemAddmin; categories.Modified = DateTime.Now; categories.Creared = DateTime.Now; if (ModelState.IsValid) { db.Categories.Add(categories); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(categories)); }
public IActionResult UploadImage(IList <IFormFile> files) { var uploadedImage = files.FirstOrDefault(); if (uploadedImage == null || uploadedImage.ContentType.ToLower().StartsWith("image/")) { var ms = new MemoryStream(); uploadedImage.OpenReadStream().CopyTo(ms); //System.Drawing.Image image = System.Drawing.Image.FromStream(ms); var imageEntity = new Image { //Id = Guid.NewGuid(), Name = uploadedImage.Name, Data = ms.ToArray(), //Width = image.Width, //Height = image.Height, ContentType = uploadedImage.ContentType }; context.Images.Add(imageEntity); context.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Create(News news, HttpPostedFileBase image) { news.ModifieddBy = Notice.SystemAddmin; news.Creared = DateTime.Now; news.CreatedBy = Notice.SystemAddmin; news.Modified = DateTime.Now; news.Image = Path.GetFileName(image.FileName); if (ModelState.IsValid) { db.News.Add(news); db.SaveChanges(); image.SaveAs(Server.MapPath(Url.Content("~/NewsImage/" + news.Id.ToString() + news.Image))); return(RedirectToAction("Index")); } return(View(news)); }
public static void Initializer(LearnContext context) { context.Database.EnsureCreated(); //check for videos if (context.Videos.Any()) { return; //db seeded } var vid = new[] { new Video { VideoName = "Introduction to python.", VideoUrl = "zpOULjyy-n8" } }; foreach (var v in vid) { context.Videos.Add(v); } context.SaveChanges(); }