コード例 #1
0
        public async Task <IActionResult> Post([FromBody] NewLaundryViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userIdentity = _mapper.Map <AppUser>(model);

            userIdentity.FirstName = model.RazaoSocial;
            userIdentity.LastName  = model.NomeFantasia;
            string password = Password.GenerateRandomPassword();

            userIdentity.PictureUrl = model.Logo;

            //creating identity
            var result = await _identityManager.CreateOrEdit(userIdentity, password);

            if (result.Error)
            {
                return(new BadRequestObjectResult(Errors.AddErrorsToModelState(result.Result, ModelState)));
            }

            //creating the laundry
            var laundry = _mapper.Map <Laundry>(model);

            laundry.IdentityId = userIdentity.Id;
            var laundryCreated = await _laundryManager.CreateOrEdit(laundry);

            return(new OkObjectResult(laundryCreated));
        }
コード例 #2
0
        public async Task <IActionResult> UpdateLogo([FromRoute] int id, [FromForm] IFormFile logo)
        {
            try
            {
                var filePath = Path.Combine(_environment.ContentRootPath, @"wwwroot/assets/Uploads/Laundries", logo.FileName);

                using (var stream = new FileStream(filePath, FileMode.Create))
                {
                    await logo.CopyToAsync(stream);
                }

                var laundry = await _laundryManager.Find(id);

                laundry.Logo = logo.FileName;

                laundry = await _laundryManager.CreateOrEdit(laundry);

                return(new OkObjectResult(laundry));
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }