Пример #1
0
        public IActionResult Create(CreateViewModel user)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = null;
                if (user.Photos != null && user.Photos.Count > 0)
                {
                    foreach (IFormFile photo in user.Photos)
                    {
                        string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images");
                        uniqueFileName = Guid.NewGuid().ToString() + "_" + photo.FileName;
                        string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                        photo.CopyTo(new FileStream(filePath, FileMode.Create));
                    }
                }

                User newUser = new User
                {
                    Name      = user.Name,
                    Email     = user.Email,
                    UserHobby = user.UserHobby,
                    PhotoPath = uniqueFileName
                };

                _userDatabase.Add(newUser);

                return(RedirectToAction("UserDetails", new { id = newUser.ID }));
            }

            return(View());
        }
        public void Handle(UserCreatedEvent handle)
        {
            var userDto = new UserDto
            {
                Id          = handle.AggregateId,
                Version     = handle.Version,
                Name        = handle.Name,
                PhoneNumber = handle.PhoneNumber,
                GenderType  = handle.GenderType,
                Address     = handle.Address,
                CreateTime  = handle.CreateTime
            };

            _userDatabase.Add(userDto);

            //TODO: Send email to target user.
        }
 public int Add(UserType userType)
 {
     return(_db.Add(userType));
 }