示例#1
0
 //CREATE
 public IActionResult Create(User user)
 {
     if (ModelState.IsValid)
     {
         _context.Add(user);
         _context.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
示例#2
0
        public ActionResult Create([Bind(Include = "RoleId,RoleName")] UserRole userRole)
        {
            if (ModelState.IsValid)
            {
                db.UserRoles.Add(userRole);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(userRole));
        }
示例#3
0
        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));
        }
示例#4
0
        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));
        }
示例#5
0
 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"));
 }
示例#6
0
        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));
        }
示例#7
0
        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));
        }
示例#8
0
        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"));
        }
示例#9
0
 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));
 }
示例#10
0
        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();
        }