Пример #1
0
 public ActionResult Create([Bind(Prefix = "post")] PostVM.PostCreateVM post, HttpPostedFileBase file)
 {
     if (ModelState.IsValid)
     {
         post.Email = User.Identity.GetUserName();
         PostDTO postDTO = new PostDTO();
         postDTO = _imapper.Map <PostVM.PostCreateVM, PostDTO>(post);
         if (file == null)
         {
             if (ConvertString.ConvertToBool(_iapiResponse.Post <PostDTO>("posts", postDTO)))
             {
                 return(RedirectToAction("Index", "Home"));
             }
         }
         else if (file != null && ImageFunction.IsImage(file.InputStream))
         {
             Image resizeImage = ImageFunction.ScaleImage(Image.FromStream(file.InputStream), (int)StatusCode.MAX_WIDTH, (int)StatusCode.MAX_HEIGHT);
             postDTO.Image = ImageFunction.imageToByteArray(resizeImage);
             if (ConvertString.ConvertToBool(_iapiResponse.Post <PostDTO>("posts", postDTO)))
             {
                 return(RedirectToAction("Index", "Home"));
             }
         }
         else
         {
             ModelState.AddModelError("", "Image is not correct file format");
             return(View(post));
         }
     }
     ModelState.AddModelError("", "Can't upload your post");
     return(View(post));
 }
Пример #2
0
        public ActionResult Register(AccountVM.RegisterViewModel user)
        {
            if (ModelState.IsValid)
            {
                UserDTO userDTO = new UserDTO();
                userDTO          = _mapper.Map <AccountVM.RegisterViewModel, UserDTO>(user);
                userDTO.Password = HashFunction.CreateHash(userDTO.Password);
                int?loggedIn = ConvertString.ConvertToInt(_iapiResponse.Post <UserDTO>("users", userDTO));
                if (loggedIn == (int)StatusCode.ISEXISTSUSER)
                {
                    ModelState.AddModelError("Email", "Email is alredy exists");
                    return(View(user));
                }

                else
                if (loggedIn != null)
                {
                    FormsAuthentication.SetAuthCookie(user.Email, false);
                    bool login = _iapiResponse.Authentication(userDTO);
                    return(RedirectToAction("Index", "Home"));
                }
            }
            ModelState.AddModelError("", "Can't register your account");
            return(View(user));
        }
Пример #3
0
        public ActionResult Create([Bind(Include = "PostId,CommentContent")] CommentVM comment)
        {
            string url = TempData["Url"] as string;

            if (ModelState.IsValid)
            {
                CommentDTO commentDTO = _imapper.Map <CommentVM, CommentDTO>(comment);
                commentDTO.Email = User.Identity.GetUserName();
                int?    result = ConvertString.ConvertToInt(_iapiResponse.Post <CommentDTO>("comments", commentDTO));
                UserDTO user   = _iapiResponse.Get <UserDTO>("users?value=" + User.Identity.GetUserName());
                comment.DisplayName = user.DisplayName;
                comment.CreateDate  = DateTime.Now;
                comment.ImageUser   = ImageFunction.ConvertImage(user.ImageUser);
                if (result == null)
                {
                    ModelState.AddModelError("", "Can not sent your comment");
                }
                return(PartialView("_CommentsPartial", comment));
            }
            return(RedirectToAction("Details", "Posts", new { id = comment.PostId, slug = url }));
        }