Пример #1
0
        public static User UserViewToModel(UserViewModel viewmodel)
        {
            User user = new User
            {
                UId = viewmodel.UId,
                Login = viewmodel.Login,
                Age = (DateTime.Now - viewmodel.BirthDay).Days / 365,
                Phone = viewmodel.Phone,
                Password = viewmodel.Password,
                FirstName = viewmodel.FirstName,
                LastName = viewmodel.LastName,
                IsActive = viewmodel.IsActive,
                ImageID = viewmodel.ImageID,
                Email = viewmodel.Email,
                BirthDay = viewmodel.BirthDay,
                DateCreated = viewmodel.DateCreated,
                DateUpdated = DateTime.Now,
                Role = viewmodel.Role
            };
            user.BlockDescription = (!user.IsActive) ? viewmodel.BlockDescription : "";

            Image img = new Image();
            if (viewmodel.Image != null)
            {
                img.IId = user.ImageID;
                img.ImageName = viewmodel.Image.FileName;

                MemoryStream target = new MemoryStream();
                viewmodel.Image.InputStream.CopyTo(target);
                img.ImageContent = target.ToArray();
                user.Image = img;
            }
            return user;
        }
 public void Edit(User item)
 {
     if (_userRepository.isActive(item.UId) && !item.IsActive)
     {
         EmailModel m = new EmailModel();
         m.To = item.Email.TrimEnd();
         m.From = "*****@*****.**";
         m.Subject = "You are banned";
         m.Body = string.Format("Sorry, but you are banned on our site. Reason:{0}.",item.BlockDescription);
         _emailService.SendEmail(m);
     }
     _userRepository.Edit(item);
 }
        public void Add(User item)
        {
            item.DateCreated = DateTime.Now;
            item.Password = MySecurity.GetHashString(item.Password);
            _userRepository.Add(item);

            EmailModel m = new EmailModel();
            m.To = item.Email.TrimEnd();
            m.From = "*****@*****.**";
            m.Subject = "Registration";
            m.Body = "You have been successfuly registeren on our site!";
            _emailService.SendEmail(m);
        }
Пример #4
0
        public static UserViewModel UserModelToView (User user)
        {
            UserViewModel viewmodel = new UserViewModel
            {
                UId = user.UId,
                Login = user.Login.TrimEnd(),
                Phone = user.Phone,
                Password = user.Password.TrimEnd(),
                FirstName = user.FirstName.TrimEnd(),
                LastName = user.LastName.TrimEnd(),
                IsActive = user.IsActive,
                BlockDescription = user.BlockDescription.TrimEnd(),
                Email = user.Email.TrimEnd(),
                BirthDay = user.BirthDay,
                ImageID = user.ImageID,
                DateCreated = user.DateCreated,
                Role = user.Role
            };

            return viewmodel;
        }