public ActionResult Register(RegisterViewModel model)
        {
            UserManager userManager = new UserManager();

            if (ModelState.IsValid)
            {
                BLResult <BlogUser> result = userManager.RegisterUser(model);

                if (result.Errors.Count > 0)
                {
                    result.Errors.ForEach(x => ModelState.AddModelError("", x));
                    return(View(model));
                }

                OkViewModel okModel = new OkViewModel()
                {
                    Title  = "Registration Okay",
                    Header = "Please check your email box to activate your account."
                };

                return(View("Ok", okModel));
            }

            return(View(model));
        }
Example #2
0
        public BLResult <BlogUser> ActiivateUser(Guid activateId)
        {
            BLResult <BlogUser> result = new BLResult <BlogUser>();

            result.Entity = userRepo.Get(x => x.ActivateGuid == activateId);

            if (result.Entity != null)
            {
                if (result.Entity.IsActive)
                {
                    //hatalara active edilmiş kullanıcı hatası eklenecek..
                    result.Errors.Add("The user is already activeted.");
                    return(result);
                }

                result.Entity.IsActive = true;
                userRepo.Update(result.Entity);
            }
            else
            {
                result.Errors.Add("No active users found.");
            }


            return(result);
        }
Example #3
0
        public BLResult <BlogUser> UpdateProfile(BlogUser data)
        {
            //TODO
            //burda zorunlu olanları kontrol edip çakışmayı engellemek gerekebilir..

            BlogUser            user   = userRepo.Get(x => x.Username == data.Username);
            BLResult <BlogUser> result = new BLResult <BlogUser>();

            if (user != null && user.Id != data.Id)
            {
                result.Errors.Add("Kullanıcı Update edilemedi..");
                return(result);
            }

            result.Entity          = userRepo.Get(x => x.Id == data.Id);
            result.Entity.Email    = data.Email;
            result.Entity.Name     = data.Name;
            result.Entity.Surname  = data.Surname;
            result.Entity.Username = data.Username;
            result.Entity.Password = data.Password;

            //TODO
            //burda da resmi alıp almadığımzı kontrol etmemiz gerekebilir.
            result.Entity.UserImageFileName = data.UserImageFileName;


            return(result);
        }
        public ActionResult Login(LoginViewModel model)
        {
            UserManager userManager = new UserManager();

            if (ModelState.IsValid)
            {
                BLResult <BlogUser> result = userManager.LoginUser(model);

                if (result.Errors.Count > 0)
                {
                    result.Errors.ForEach(x => ModelState.AddModelError("", x));
                    return(View(model));
                }

                Session["login"] = result.Entity;
                Session.Timeout  = 30;

                BlogUser user = Session["login"] as BlogUser;



                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
        public ActionResult UserActivate(Guid activate_guid)
        {
            UserManager         user   = new UserManager();
            BLResult <BlogUser> result = user.ActiivateUser(activate_guid);

            if (result.Errors.Count > 0)
            {
                ErrorViewModel errorModel = new ErrorViewModel()
                {
                    Title = "Invalid Registration",
                };
                errorModel.Items = result.Errors;

                return(View("Error", errorModel));
            }

            OkViewModel okModel = new OkViewModel()
            {
                Title          = "Registration Susccessfull.",
                RedirectingUrl = "/Home/Login"
            };

            okModel.Items.Add("Please activate your account via activate mail. Check your e-mail box.");

            return(View("Ok", okModel));
        }
Example #6
0
        public ActionResult <BLResult <User> > PostUser(User user)
        {
            BLResult <User> result = userTransactionScript.AddUser(user);

            if (!result.Success)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
Example #7
0
        public ActionResult <BLResult <SimpleUser> > Authenticate([FromBody] SimpleUser userParam)
        {
            BLResult <SimpleUser> result = userTransactionScript.Authenticate(userParam);

            if (!result.Success)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
Example #8
0
        public BLResult <BlogUser> GetUserById(int id)
        {
            BLResult <BlogUser> result = new BLResult <BlogUser>();

            result.Entity = userRepo.Get(x => x.Id == id);

            if (result.Entity == null)
            {
                result.Errors.Add("Kullanıcı Bulunamadı.");
            }


            return(result);
        }
Example #9
0
        public BLResult <BlogUser> RegisterUser(RegisterViewModel user)
        {
            BLResult <BlogUser> result = new BLResult <BlogUser>();

            BlogUser userToInsert = userRepo.Get(x => x.Username == user.Username || x.Email == user.Email);

            if (userToInsert != null)
            {
                if (userToInsert.Username == user.Username)
                {
                    result.Errors.Add("Username is not available.");
                }
                if (userToInsert.Email == user.Email)
                {
                    result.Errors.Add("Email is not available.");
                }
            }
            else
            {
                int check = userRepo.Insert(new BlogUser {
                    Username         = user.Username,
                    Email            = user.Email,
                    Password         = user.Password,
                    ActivateGuid     = Guid.NewGuid(),
                    Name             = "name",
                    Surname          = "surname",
                    CreatedOn        = DateTime.Now,
                    ModifiedOn       = DateTime.Now,
                    ModifiedUsername = AppHelper.Common.GetUsername(),
                    IsActive         = false,
                    IsAdmin          = false
                });

                if (check > 0)
                {
                    result.Entity = userRepo.Get(x => x.Username == user.Username);


                    string siteUri   = ConfigHelper.Get <string>("SiteRootUri");
                    string activeUri = $"{siteUri}/Home/UserActivate/{result.Entity.ActivateGuid}";
                    string body      = $"Merhaba {result.Entity.Username} {result.Entity.Surname} <br><br> Hesabınızı" +
                                       $"aktifleştirmek için <a href='{activeUri}' target='_blank'>tıklayınız</a>.";

                    MailHelper.SendMail(body, result.Entity.Email, "Hesap Aktifleştirme");
                }
            }

            return(result);
        }
Example #10
0
        public async Task <ActionResult> PostMovie([FromForm] MovieModel movie)
        {
            // Only Admin users are allowed to perform this action
            if (!IsUserAdminAutenticated())
            {
                return(Unauthorized(new { message = "Not allowed" }));
            }
            // Validating parameters
            if (movie == null)
            {
                return(BadRequest());
            }

            // Uploading Image to Storage first
            StorageAccountService storageService = new StorageAccountService(Configuration);
            StorageResult         storageResult  = await storageService.UploadImageToStorage(movie.Image, movie.Title);

            if (storageResult.Success)
            {
                // Save movie in Database
                Movie movieDb = new Movie()
                {
                    Title        = movie.Title,
                    Description  = movie.Description,
                    Stock        = 0,
                    SalePrice    = movie.SalePrice,
                    RentalPrice  = movie.RentalPrice,
                    LikesCounter = 0,
                    Image        = storageResult.Uri,
                    IsAvailable  = true
                };
                BLResult <Movie> blResult = movieTransactionScript.AddMovie(movieDb);

                if (blResult.Success)
                {
                    return(CreatedAtAction("GetMovie", new { id = blResult.Item.IdMovie }, blResult.Item));
                }
                else
                {
                    return(StatusCode(500, blResult));
                }
            }
            else
            {
                return(StatusCode(500, storageResult));
            }
        }
Example #11
0
        public ActionResult <BLResult <User> > PostInventory(Inventory inventory)
        {
            // Only Admin users are allowed to perform this action
            if (!IsUserAdminAutenticated())
            {
                return(Unauthorized(new { message = "Not allowed" }));
            }

            BLResult <Inventory> result = inventoryTransactionScript.AddInventory(inventory);

            if (!result.Success)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
Example #12
0
        public ActionResult <Movie> GetUser()
        {
            int idUser = GetCurrentUser();

            if (idUser == -1)
            {
                return(NotFound(new { message = "Invalid JWT" }));
            }

            BLResult <User> result = userTransactionScript.GetUserById(idUser);

            if (!result.Success)
            {
                return(NotFound(new { message = "User not found" }));
            }

            return(Ok(result.Item));
        }
Example #13
0
        public BLResult <BlogUser> LoginUser(LoginViewModel model)
        {
            BLResult <BlogUser> result = new BLResult <BlogUser>();

            result.Entity = userRepo.Get(x => x.Username == model.Username && x.Password == model.Password);

            if (result.Entity != null)
            {
                if (!result.Entity.IsActive)
                {
                    result.Errors.Add("User is not active. Please check your emails for activation..");
                }
            }
            else
            {
                result.Errors.Add("Invalid email or password. Please try again.");
            }

            return(result);
        }
Example #14
0
        public ActionResult <Movie> GetMovie(int id)
        {
            BLResult <Movie> result = movieTransactionScript.GetMovieById(id);

            if (!result.Success)
            {
                return(NotFound());
            }

            // If user is admin can get any movie
            if (!IsUserAdminAutenticated())
            {
                if (result.Item.IsAvailable == false)
                {
                    return(Forbid());
                }
            }

            return(Ok(result.Item));
        }
Example #15
0
        public IActionResult PutRental(Rental rental)
        {
            // Only logged users are allowed to perform this action
            int idUser = GetCurrentUser();

            if (idUser == -1)
            {
                return(Unauthorized(new { message = "Not allowed. Login." }));
            }

            rental.IdUser = idUser;
            BLResult <Rental> result = rentalTransactionScript.ReturnRental(rental, idUser);

            if (!result.Success)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
Example #16
0
        public ActionResult <BLResult <Sale> > PostSale(Sale sale)
        {
            // Only logged users are allowed to perform this action
            int idUser = GetCurrentUser();

            if (idUser == -1)
            {
                return(Unauthorized(new { message = "Not allowed. Login." }));
            }

            sale.IdUser = idUser;
            BLResult <Sale> result = saleTransactionScript.AddSale(sale);

            if (!result.Success)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
        public Comment Delete(Comment data)
        {
            Comment            comment = commentRepo.Get(x => x.Id == data.Id);
            BLResult <Comment> result  = new BLResult <Comment>();

            if (comment != null && data.Id != comment.Id)
            {
                result.Errors.Add("yorum silme işleminde Comment Manager'da hata");
                return(null);
            }

            int check = commentRepo.Remove(comment);

            if (check > 0)
            {
                return(comment);
            }
            else
            {
                return(null);
            }
        }
        public ActionResult EditProfile()
        {
            BlogUser currentUser = null;

            currentUser = Session["login"] as BlogUser;

            UserManager         usermanager = new UserManager();
            BLResult <BlogUser> result      = usermanager.GetUserById(currentUser.Id);

            if (result.Errors.Count > 0)
            {
                ErrorViewModel errorModel = new ErrorViewModel()
                {
                    Title = "Invalid Profile Update Operation",
                };
                errorModel.Items = result.Errors;

                return(View("Error", errorModel));
            }

            return(View(result.Entity));
        }
Example #19
0
        public async Task <IActionResult> PatchUser(int id, [FromBody] JsonPatchDocument <User> patchUser)
        {
            // Only Admin users are allowed to perform this action
            if (!IsUserAdminAutenticated())
            {
                return(Unauthorized(new { message = "Not allowed" }));
            }

            if (!ModelState.IsValid)
            {
                return(new BadRequestObjectResult(ModelState));
            }

            BLResult <User> result = await userTransactionScript.PatchUser(patchUser, id);

            if (!result.Success)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
Example #20
0
        public ActionResult <User> DeleteLike(int idUser, int idMovie)
        {
            // Only the user is allowed to perform this action
            if (!IsAuthenticatedUser(idUser))
            {
                return(Unauthorized(new { message = "Not allowed" }));
            }

            Liked liked = new Liked()
            {
                IdMovie = idMovie,
                IdUser  = idUser
            };

            BLResult <Liked> blResult = likedTransactionScript.RemoveLike(liked);

            if (!blResult.Success)
            {
                return(StatusCode(500, blResult));
            }

            return(Ok(new { message = $"User: {liked.IdUser} removed the LIKE to the Movie: {liked.IdMovie}" }));
        }
Example #21
0
        public BLResult <Category> AddCategory(CategoryViewModel categoryModel)
        {
            BLResult <Category> result = new BLResult <Category>();

            //TODO
            //eper not aynı başlıkla açılırsa izin verip vermemeye karar verilsin..
            //aynı başlık kullanılmıcaksa result.error eklensin..

            //TODO
            //Categoryid geldiği için ekranda öncelikle category seçtirmemiz lazım
            int check = categoryRepo.Insert(new Category
            {
                Title       = categoryModel.Title,
                Description = categoryModel.Description
            });

            if (check > 0)
            {
                result.Entity = categoryRepo.Get(x => x.Title == categoryModel.Title);
            }

            return(result);
        }
        public BLResult <Comment> AddComment(string text, int noteid, BlogUser user)
        {
            BLResult <Comment> result = new BLResult <Comment>();

            Note not  = noteRepo.Get(x => x.Id == noteid);
            Note note = not;

            int check = commentRepo.Insert(new Comment {
                CreatedOn        = DateTime.Now,
                ModifiedOn       = DateTime.Now,
                ModifiedUsername = AppHelper.Common.GetUsername(),
                User             = user,
                Text             = text,
                Note             = note
            });

            if (check > 0)
            {
                result.Entity = commentRepo.Get(x => x.Text == text);
            }

            return(result);
        }
        public ActionResult EditProfile(BlogUser user, HttpPostedFileBase ProfileImage)
        {
            if (ProfileImage != null &&
                (ProfileImage.ContentType == "image/jpeg" ||
                 ProfileImage.ContentType == "image/jpg" ||
                 ProfileImage.ContentType == "image/jpeg"))
            {
                string filename = $"user_{user.Id}.{ProfileImage.ContentType.Split('/')[1]}";

                ProfileImage.SaveAs(Server.MapPath($"~/images/{filename}"));
                user.UserImageFileName = filename;
            }

            UserManager         usermanager = new UserManager();
            BLResult <BlogUser> result      = usermanager.UpdateProfile(user);

            if (result.Errors.Count > 0)
            {
                ErrorViewModel errorModel = new ErrorViewModel()
                {
                    Title          = "Profil Güncelleme Başarısız",
                    RedirectingUrl = "/Home/EditProfile"
                };
                errorModel.Items = result.Errors;

                return(View("Error", errorModel));
            }

            //kullanıcı güncellendiği için sessionda güncellendi..
            Session["login"] = result.Entity;

            return(RedirectToAction("ShowProfile"));


            return(View());
        }
Example #24
0
        public BLResult <Note> AddNote(NoteViewModel note)
        {
            BLResult <Note> result = new BLResult <Note>();

            //TODO
            //eper not aynı başlıkla açılırsa izin verip vermemeye karar verilsin..
            //aynı başlık kullanılmıcaksa result.error eklensin..

            //TODO
            //Categoryid geldiği için ekranda öncelikle category seçtirmemiz lazım
            int check = noteRepo.Insert(new Note
            {
                Title      = note.Title,
                Content    = note.Content,
                CategoryId = note.CategoryId
            });

            if (check > 0)
            {
                result.Entity = noteRepo.Get(x => x.Title == note.Title);
            }

            return(result);
        }
        public Comment Update(Comment data)
        {
            Comment            comment = commentRepo.Get(x => x.Id == data.Id);
            BLResult <Comment> result  = new BLResult <Comment>();

            if (comment != null && data.Id != comment.Id)
            {
                result.Errors.Add("yorum güncellenmesinde Comment Manager'da hata");
                return(null);
            }

            comment.Text = data.Text;

            int check = commentRepo.Insert(comment);

            if (check > 0)
            {
                return(comment);
            }
            else
            {
                return(null);
            }
        }