Пример #1
0
        //Hiding method  //for admin-user-insert
        public new MessageResult <EUser> Insert(EUser model)
        {
            MessageResult <EUser> messageResult = new MessageResult <EUser>();

            messageResult.Result = Find(x => x.Username == model.Username || x.Email == model.Email);

            if (messageResult.Result != null)
            {
                if (messageResult.Result.Username == model.Username)
                {
                    messageResult.AddError(ErrorMessageCodes.UserNameAlreadyExists, "You cannot re-register with a registered Username.");
                }
                if (messageResult.Result.Email == model.Email)
                {
                    messageResult.AddError(ErrorMessageCodes.EmailAdresAlreadyExists, "You cannot re-register with a registered E-mail address.");
                }
            }
            else
            {
                messageResult.Result = model;
                messageResult.Result.ProfileImageFileName = "DefaultUser.jpg";
                messageResult.Result.ActiveGuid           = Guid.NewGuid();

                if (base.Insert(messageResult.Result) == 0)
                {
                    messageResult.AddError(ErrorMessageCodes.UserCouldNotInserted, "User could not be saved");
                }
            }

            return(messageResult);
        }
Пример #2
0
        public MessageResult <ENote> RemoveNoteById(int id)
        {
            LikeManager    likeManager    = new LikeManager();
            CommentManager commentManager = new CommentManager();

            MessageResult <ENote> res = new MessageResult <ENote>();

            res.Result = Find(x => x.Id == id);

            if (res.Result != null)
            {
                foreach (EComment item in res.Result.Comments.ToList())
                {
                    commentManager.Delete(item);
                }

                foreach (ELiked like in res.Result.Likes.ToList())
                {
                    likeManager.Delete(like);
                }

                if (Delete(res.Result) == 0)
                {
                    res.AddError(ErrorMessageCodes.CategoryCouldNotRemove, "Note could not be deleted.");
                }
                return(res);
            }
            else
            {
                res.AddError(ErrorMessageCodes.NoteCouldNotFind, "Note could not find.");
                return(res);
            }
        }
Пример #3
0
        //for register user
        public MessageResult <EUser> RegisterUser(RegisterViewModel model)
        {
            MessageResult <EUser> messageResult = new MessageResult <EUser>();

            messageResult.Result = Find(x => x.Username == model.Username || x.Email == model.Email);

            if (messageResult.Result != null)
            {
                if (messageResult.Result.Username == model.Username)
                {
                    messageResult.AddError(ErrorMessageCodes.UserNameAlreadyExists, "UserName already Exists!");
                }
                if (messageResult.Result.Email == model.Email)
                {
                    messageResult.AddError(ErrorMessageCodes.EmailAdresAlreadyExists, "E-Mail address already exists!");
                }
            }
            else
            {
                DateTime now      = DateTime.Now;
                int      dbResult = base.Insert(new EUser()
                {
                    Username             = model.Username,
                    Email                = model.Email,
                    Password             = model.Password,
                    ActiveGuid           = Guid.NewGuid(),
                    IsActive             = false,
                    IsAdmin              = false,
                    ProfileImageFileName = "DefaultUser.jpg"
                });

                if (dbResult > 0)
                {
                    messageResult.Result = Find(x => x.Username == model.Username && x.Email == model.Email);

                    //send to mail for active
                    string siteUri     = ConfigHelper.Get <string>("SiteRootUri");
                    string activateUri = $"{siteUri}/Home/UserActive/{messageResult.Result.ActiveGuid}";
                    string body        = $"Hello {messageResult.Result.Username};<br><br>" +
                                         $"To active your account <a href='{activateUri}' target='_blank'>click here</a>";
                    MailHelper.SendMail(body, messageResult.Result.Email, "MyNote Account Activation");
                }
            }

            return(messageResult);
        }
Пример #4
0
        public MessageResult <EUser> RemoveUserById(int id)
        {
            MessageResult <EUser> res = new MessageResult <EUser>();

            res.Result = Find(x => x.Id == id);
            if (res.Result == null)
            {
                res.AddError(ErrorMessageCodes.UserCouldNotFind, "User could not find.");
                return(res);
            }

            if (Delete(res.Result) == 0)
            {
                res.AddError(ErrorMessageCodes.UserCouldNotRemove, "User could not be deleted.");
            }
            return(res);
        }
Пример #5
0
        public MessageResult <ECategory> RemoveCategoryById(int id)
        {
            NoteManager    noteManager    = new NoteManager();
            LikeManager    likeManager    = new LikeManager();
            CommentManager commentManager = new CommentManager();

            MessageResult <ECategory> res = new MessageResult <ECategory>();

            res.Result = Find(x => x.Id == id);
            if (res.Result != null)
            {
                //delete
                foreach (ENote note in res.Result.Notes.ToList())
                {
                    //delete like
                    foreach (ELiked like in note.Likes.ToList())
                    {
                        likeManager.Delete(like);
                    }

                    //comment delete
                    foreach (EComment comment in note.Comments.ToList())
                    {
                        commentManager.Delete(comment);
                    }

                    //note delete
                    noteManager.Delete(note);
                }

                if (Delete(res.Result) == 0)
                {
                    res.AddError(ErrorMessageCodes.CategoryCouldNotRemove, "Category could not be deleted.");
                }
                return(res);
            }
            else
            {
                res.AddError(ErrorMessageCodes.UserCouldNotFind, "User could not find.");
            }

            return(res);
        }
Пример #6
0
        //search by id
        public MessageResult <EUser> GetUserById(int id)
        {
            MessageResult <EUser> messageResult = new MessageResult <EUser>();

            messageResult.Result = Find(x => x.Id == id);
            if (messageResult.Result == null)
            {
                messageResult.AddError(ErrorMessageCodes.UserNotFound, "User not found.");
            }
            return(messageResult);
        }
        public MessageResult <EComment> RemoveCommentById(int id)
        {
            MessageResult <EComment> res = new MessageResult <EComment>();

            res.Result = Find(x => x.Id == id);

            if (res.Result != null)
            {
                if (Delete(res.Result) == 0)
                {
                    res.AddError(ErrorMessageCodes.CommentCouldNotRemove, "Comment could not be deleted.");
                }
                return(res);
            }
            else
            {
                res.AddError(ErrorMessageCodes.CommentCouldNotFind, "Comment could not find.");
                return(res);
            }
        }
Пример #8
0
        //login
        public MessageResult <EUser> LoginUser(LoginViewModel model)
        {
            MessageResult <EUser> messageResult = new MessageResult <EUser>();

            messageResult.Result = Find(x => x.Username == model.Username && x.Password == model.Password);

            if (messageResult.Result == null)
            {
                messageResult.AddError(ErrorMessageCodes.UserNameorPassWrong, "Username or password wrong!");
            }
            else
            {
                if (!messageResult.Result.IsActive)
                {
                    messageResult.AddError(ErrorMessageCodes.UserIsnotActive, "User is not active");
                    messageResult.AddError(ErrorMessageCodes.CheckYourEmail, "Please check your E-Mail.");
                }
            }

            return(messageResult);
        }
Пример #9
0
        //Profile update
        public MessageResult <EUser> UpdateProfile(EUser model)
        {
            MessageResult <EUser> res = new MessageResult <EUser>();

            res.Result = Find(x => x.Id != model.Id && (x.Username == model.Username || x.Email == model.Email));

            if (res.Result != null && res.Result.Id != model.Id)
            {
                if (res.Result.Username == model.Username)
                {
                    res.AddError(ErrorMessageCodes.UserNameAlreadyExists, "UserName already exists.");
                }

                if (res.Result.Email == model.Email)
                {
                    res.AddError(ErrorMessageCodes.EmailAdresAlreadyExists, "E-Mail already exists.");
                }

                return(res);
            }

            res.Result          = Find(x => x.Id == model.Id);
            res.Result.Email    = model.Email;
            res.Result.Name     = model.Name;
            res.Result.Surname  = model.Surname;
            res.Result.Password = model.Password;
            res.Result.Username = model.Username;

            if (string.IsNullOrEmpty(model.ProfileImageFileName) == false)
            {
                res.Result.ProfileImageFileName = model.ProfileImageFileName;
            }

            if (base.Update(res.Result) == 0)
            {
                res.AddError(ErrorMessageCodes.ProfileCouldNotUpdated, "Profile could not be updated.");
            }

            return(res);
        }
Пример #10
0
        //Activate
        public MessageResult <EUser> ActivateUser(Guid guid)
        {
            MessageResult <EUser> messageResult = new MessageResult <EUser>();

            messageResult.Result = Find(x => x.ActiveGuid == guid);
            if (messageResult.Result != null)
            {
                if (messageResult.Result.IsActive)
                {
                    messageResult.AddError(ErrorMessageCodes.UserAlreadyActive, "User already active.");
                    return(messageResult);
                }
                messageResult.Result.IsActive = true;
                Update(messageResult.Result);
            }
            else
            {
                messageResult.AddError(ErrorMessageCodes.ActivateIdDoesNotExists, "Activate id does not exists.");
            }

            return(messageResult);
        }
Пример #11
0
        public new MessageResult <EUser> Update(EUser model)
        {
            MessageResult <EUser> res = new MessageResult <EUser>();

            res.Result = Find(x => x.Id != model.Id && (x.Username == model.Username || x.Email == model.Email));

            if (res.Result != null && res.Result.Id != model.Id)
            {
                if (res.Result.Username == model.Username)
                {
                    res.AddError(ErrorMessageCodes.UserNameAlreadyExists, "User name already exists.");
                }

                if (res.Result.Email == model.Email)
                {
                    res.AddError(ErrorMessageCodes.EmailAdresAlreadyExists, "E-Mail address already exists.");
                }

                return(res);
            }

            res.Result          = Find(x => x.Id == model.Id);
            res.Result.Email    = model.Email;
            res.Result.Name     = model.Name;
            res.Result.Surname  = model.Surname;
            res.Result.Password = model.Password;
            res.Result.Username = model.Username;
            res.Result.IsActive = model.IsActive;
            res.Result.IsAdmin  = model.IsAdmin;

            if (base.Update(res.Result) == 0)
            {
                res.AddError(ErrorMessageCodes.UserCouldNotUpdated, "User could not be update.");
            }

            return(res);
        }