Ejemplo n.º 1
0
        public ActionResult Create(MangaDetail item)
        {
            var path     = "";
            var fileName = "";
            var user     = (UserLogin)Session[Constants.USER_SESSION];

            if (item.imgFile != null)
            {
                fileName = item.imgFile.FileName;
                if (item.imgFile.ContentLength > 0)
                {
                    var manga = new Manga();
                    manga.mName        = item.displayName;
                    manga.publishedAt  = DateTime.Now;
                    manga.updatedAt    = DateTime.Now;
                    manga.mAuthor      = item.author;
                    manga.CreatedBy    = user.UserId;
                    manga.mDescription = item.description;
                    MangaDao dao = new MangaDao();
                    int      id  = dao.AddManga(manga);
                    AddCategory(id, item.categories);

                    if (Path.GetExtension(fileName).ToLower() == ".jpg" ||
                        Path.GetExtension(fileName).ToLower() == ".png" ||
                        Path.GetExtension(fileName).ToLower() == ".gif" ||
                        Path.GetExtension(fileName).ToLower() == ".jpeg")
                    {
                        string currentDir = Path.Combine(HttpRuntime.AppDomainAppPath, "Image");
                        if (!Directory.Exists(Path.Combine(currentDir, id.ToString())))
                        {
                            Directory.CreateDirectory(Path.Combine(currentDir, id.ToString()));
                        }
                        string dir = Path.Combine(currentDir, id.ToString());
                        path = Path.Combine(dir, fileName);
                        item.imgFile.SaveAs(path);
                        var _manga = db.Mangas.Where(i => i.mId == id).FirstOrDefault();
                        _manga.image = "/Image/" + manga.mId.ToString() + "/" + item.imgFile.FileName;
                        db.SaveChanges();
                    }
                }
            }
            return(RedirectToAction("Index", "Manage"));
        }
Ejemplo n.º 2
0
 public int Insert(User entity)
 {
     db.Users.Add(entity);
     db.SaveChanges();
     return(entity.uId);
 }
Ejemplo n.º 3
0
 public int AddManga(Manga entity)
 {
     db.Mangas.Add(entity);
     db.SaveChanges();
     return(entity.mId);
 }