Ejemplo n.º 1
0
        public void edituserfromadmin(EditUserViewModel edit)
        {
            User user = getuserbyid(edit.UserID);

            user.Email = edit.Email;
            if (!string.IsNullOrEmpty(edit.Password))
            {
                user.Password = PasswordHelper.EncodePasswordMd5(edit.Password);
            }

            if (edit.UserAvatar != null)
            {
                if (edit.AvatarName != "Deafault.jpg")
                {
                    string dImagepath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/UserAvatar", edit.AvatarName);
                    if (File.Exists(dImagepath))
                    {
                        File.Delete(dImagepath);
                    }
                }
                user.UserAvatar = Namegenerator.GenerateUniqcode() + Path.GetExtension(edit.UserAvatar.FileName);
                string Imagepath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/UserAvatar", user.UserAvatar);
                using (var stream = new FileStream(Imagepath, FileMode.Create))
                {
                    edit.UserAvatar.CopyTo(stream);
                }
            }
            _db.Users.Update(user);
            _db.SaveChanges();
        }
Ejemplo n.º 2
0
        public void Editprofile(string username, EditprofileViewModel edit)
        {
            if (edit.UserAvatar != null)
            {
                string Imagepath = "";
                if (edit.AvatarName != "Deafault.jpg")
                {
                    Imagepath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/UserAvatar", edit.AvatarName);
                    if (File.Exists(Imagepath))
                    {
                        File.Delete(Imagepath);
                    }
                }
                edit.AvatarName = Namegenerator.GenerateUniqcode() + Path.GetExtension(edit.UserAvatar.FileName);
                Imagepath       = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/UserAvatar", edit.AvatarName);
                using (var stream = new FileStream(Imagepath, FileMode.Create))
                {
                    edit.UserAvatar.CopyTo(stream);
                }
            }
            var user = getuserbyusername(username);

            user.UserName   = edit.UserName;
            user.Email      = edit.Email;
            user.UserAvatar = edit.AvatarName;

            updateuser(user);
        }
Ejemplo n.º 3
0
        public int Addcourse(Course course, IFormFile imgCourse, IFormFile democourse)
        {
            course.Createdate     = DateTime.Now;
            course.CourseImagname = "no-image.png";
            if (imgCourse != null && imgCourse.Isimage())
            {
                course.CourseImagname = Namegenerator.GenerateUniqcode() + Path.GetExtension(imgCourse.FileName);
                string imagepath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/Course/Image", course.CourseImagname);

                using (var stream = new FileStream(imagepath, FileMode.Create))
                {
                    imgCourse.CopyTo(stream);
                }
                ImageConvertor imageresizer = new ImageConvertor();
                string         thumpath     = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/Course/thumb", course.CourseImagname);
                imageresizer.Image_resize(imagepath, thumpath, 150);
            }
            if (democourse != null)
            {
                course.DemofileName = Namegenerator.GenerateUniqcode() + Path.GetExtension(democourse.FileName);
                string demopath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/Course/demos", course.DemofileName);
                using (var stream = new FileStream(demopath, FileMode.Create))
                {
                    democourse.CopyTo(stream);
                }
            }

            _db.Add(course);
            _db.SaveChanges();
            return(course.CourseID);
        }
Ejemplo n.º 4
0
        public bool ActiveAccount(string activecode)
        {
            var user = _db.Users.SingleOrDefault(p => p.Activecode == activecode);

            if (user == null || user.isActive)
            {
                return(false);
            }
            user.isActive   = true;
            user.Activecode = Namegenerator.GenerateUniqcode();
            _db.SaveChanges();
            return(true);
        }
        public IActionResult Register(RegisterViewModel register)
        {
            if (!ModelState.IsValid)
            {
                return(View(register));
            }
            if (_UserService.isExistUserName(register.UserName))
            {
                ModelState.AddModelError("UserName", "نام کاربری م.جود نمی باشد");
                return(View(register));
            }
            if (_UserService.isExistEmail(FixedText.Fixemail(register.Email)))
            {
                ModelState.AddModelError("Email", "ایمیل تکراری می باشد");
                return(View(register));
            }

            User user = new User()
            {
                Activecode   = Namegenerator.GenerateUniqcode(),
                Email        = FixedText.Fixemail(register.Email),
                isActive     = false,
                Password     = PasswordHelper.EncodePasswordMd5(register.Password),
                Registerdate = DateTime.Now,
                UserName     = register.UserName,
                UserAvatar   = "Deafault.jpg",
            };

            _UserService.adduser(user);

            #region send activison email

            string body = _viewRender.RenderToStringAsync("activisionemail", user);
            SendEmail.Send(user.Email, "فعال سازی", body);


            #endregion


            return(View("SuccessRegister", user));
        }
Ejemplo n.º 6
0
        public int adduserfromadmin(CreateUserViewModel create)
        {
            User aduser = new User();

            aduser.Password     = PasswordHelper.EncodePasswordMd5(create.Password);
            aduser.Activecode   = Namegenerator.GenerateUniqcode();
            aduser.Email        = create.Email;
            aduser.isActive     = true;
            aduser.Registerdate = DateTime.Now;
            aduser.UserName     = create.UserName;
            #region useravatar
            if (create.UserAvatar != null)
            {
                string Imagepath = "";
                aduser.UserAvatar = Namegenerator.GenerateUniqcode() + Path.GetExtension(create.UserAvatar.FileName);
                Imagepath         = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/UserAvatar", aduser.UserAvatar);
                using (var stream = new FileStream(Imagepath, FileMode.Create))
                {
                    create.UserAvatar.CopyTo(stream);
                }
            }
            #endregion
            return(adduser(aduser));
        }