public ActionResult SignUp(string login, string password) { KnihovnaUser user = new KnihovnaUser(); user.Name = login; user.AuthLevel = 0; user.CommentsNumber = 0; user.Exp = 0; user.Id = Books.Counter(); user.ImageName = "avatar.png"; user.JoinedDateTime = DateTime.Now; user.LikesNumber = 0; user.Login = login; user.Money = 0; user.Password = password; user.AuthLevel = 0; user.PostsNumber = 0; user.CommentsNumber = 0; user.Reputation = 0; user.Surname = ""; user.WelcomeText = ""; user.Role = new KnihovnaRoleDao().GetbyId(2); user.RestrictedTo = DateTime.MinValue; KnihovnaUserDao dao = new KnihovnaUserDao(); dao.Create(user); KnihovnaUserRoleDao rd = new KnihovnaUserRoleDao(); KnihovnaUserRole r = new KnihovnaUserRole(); r.Id = Books.Counter(); r.Data = -1; r.DateFrom = DateTime.Now; r.DateTo = DateTime.MinValue; r.RoleId = 2; r.UserId = user.Id; rd.Create(r); NovinkyGenerator.PridatNovinku(user, dao.GetByLogin(user.Name).Id); return(RedirectToAction("Index")); }
public ActionResult Add(string description, int topicId, int reply, string type = "", string typeData = "", string sumText = "") { if (type != "create" && type != "") { if (typeData == "komentEdit") { Edit(int.Parse(type), description); } else { EditPrispevek(topicId, description, sumText); } } else { KnihovnaKomentareDao knihovnaKomentareDao = new KnihovnaKomentareDao(); KnihovnaKomentare komentar = new KnihovnaKomentare(); komentar.Id = Books.Counter(); komentar.Content = description; komentar.OwnerId = new KnihovnaUserDao().GetByLogin(User.Identity.Name); komentar.Date = DateTime.Now; komentar.TopicId = topicId; komentar.ReplyId = reply; knihovnaKomentareDao.Create(komentar); KnihovnaUserDao dao = new KnihovnaUserDao(); KnihovnaUser user = dao.GetByLogin(User.Identity.Name); UserStats.NewComment(dao, user); NovinkyGenerator.PridatNovinku(komentar, user.Id); } return(Redirect(this.Request.UrlReferrer.AbsolutePath)); }
public ActionResult Add(Book book, HttpPostedFileBase picture, int categoryId) { //if (ModelState.IsValid) { KnihovnaUserDao d = new KnihovnaUserDao(); KnihovnaUser u = d.GetByLogin(User.Identity.Name); KnihovnaKategorieDao k = new KnihovnaKategorieDao(); Book b = new Book() { Name = book.Name, Author = book.Author, PublishedYear = book.PublishedYear, Id = Books.Counter(), Description = book.Description, OwnerId = u, Kategorie = k.GetbyId(2), LastEditDateTime = DateTime.Now, Version = 1, IsPayed = false, UnlockPrice = 0, MinimalLevel = 0 }; if (picture != null) { var z = picture.ContentLength; if (picture.ContentType == "image/jpeg" || picture.ContentType == "image/png") { Image image = Image.FromStream(picture.InputStream); Image smalImage = ImageHelper.ScaleImage(image, 200, 200); Bitmap btmBitmap = new Bitmap(smalImage); Guid guid = Guid.NewGuid(); string imageName = guid.ToString() + ".jpg"; btmBitmap.Save(Server.MapPath("~/Uploads/Book/") + imageName, ImageFormat.Jpeg); // Je potřeba namapovat cestu! btmBitmap.Dispose(); image.Dispose(); b.ImageName = imageName; } } BookCategoryDao bookCategoryDao = new BookCategoryDao(); BookCategory bookCategory = bookCategoryDao.GetbyId(5); b.Category = bookCategory; b.Author = "nějaká děvka"; b.SectionId = categoryId; BookDao bookDao = new BookDao(); int identifier = (int)bookDao.Create(b); BookVersionDao bv = new BookVersionDao(); BookVersion v = new BookVersion(); v.Text = b.Description; v.ChangedBy = u.Id; v.Date = DateTime.Now; v.Id = Books.Counter(); v.IsApproved = true; v.IsSuggestion = false; v.PostId = identifier; v.SumText = "Původní verze"; v.Version = 1; bv.Create(v); LevelUp.NewPost(u, d); NovinkyGenerator.PridatNovinku(b, u.Id); // Notifikace TempData["scs"] = "V pořádku"; } // else { return(View("Create", book)); // Vrátím vstupní data } return(RedirectToAction("Index")); }
public ActionResult Add(Book book, HttpPostedFileBase picture, int categoryId) { if (ModelState.IsValid) { Book b = new Book() { Name = book.Name, Author = book.Author, PublishedYear = book.PublishedYear, Id = Books.Counter(), Description = book.Description, OwnerId = new KnihovnaUserDao().GetByLogin(User.Identity.Name), Kategorie = new KnihovnaKategorieDao().GetbyId(2), LastEditDateTime = DateTime.Now, Version = 1, IsPayed = false, UnlockPrice = 0, MinimalLevel = 0 }; if (picture != null) { var z = picture.ContentLength; if (picture.ContentType == "image/jpeg" || picture.ContentType == "image/png") { Image image = Image.FromStream(picture.InputStream); Image smalImage = ImageHelper.ResizeImageHighQuality(image, 200, 200); Bitmap btmBitmap = new Bitmap(smalImage); Guid guid = Guid.NewGuid(); string imageName = guid.ToString() + ".jpg"; btmBitmap.Save(Server.MapPath("~/Uploads/Book/") + imageName, ImageFormat.Jpeg); // Je potřeba namapovat cestu! btmBitmap.Dispose(); image.Dispose(); b.ImageName = imageName; } } BookCategoryDao bookCategoryDao = new BookCategoryDao(); BookCategory bookCategory = bookCategoryDao.GetbyId(categoryId); b.Category = bookCategory; BookDao bookDao = new BookDao(); bookDao.Create(b); NovinkyGenerator.PridatNovinku(b, new KnihovnaUserDao().GetByLogin(User.Identity.Name).Id); // Notifikace TempData["scs"] = "V pořádku"; } else { return(View("Create", book)); // Vrátím vstupní data } return(RedirectToAction("Index")); }