public async Task <IActionResult> UploadImg([FromForm] IFormFile file, [FromForm] string id) { if (file != null && id != null) { string avatar = await _imageHandler.UploadImage(file); var user = _accountService.GetById(id); var model = new UpdateByFreelancerUserVm { Id = id, Avatar = avatar, Address = user.Address, PhoneNumber = user.PhoneNumber }; if (model.Avatar != "Invalid image file") { return(Ok(_accountService.UpdateByFreelancer(model))); } else { return(BadRequest("Este tipo de archivo no es admitido")); } } else { return(BadRequest("Ocurrio un error al cargar la imagen")); } }
public bool Add(FreelancerVm entity) { try { UpdateByFreelancerUserVm user = new UpdateByFreelancerUserVm { Id = entity.ApplicationUserId, PhoneNumber = entity.PhoneNumber, Avatar = entity.Avatar, Address = entity.Address }; _accountService.UpdateByFreelancer(user); //preparamos el model del freelancer var freelancer = new Freelancer { CreatedAt = _dateTime, ApplicationUserId = entity.ApplicationUserId, Biography = entity.Biography, Historial = entity.Address, Interest = entity.Interest, Lenguaje = entity.Lenguaje, Level = entity.Level, PriceHour = entity.PriceHour, Rating = entity.Rating, Lat = entity.Lat, Long = entity.Long, Profesion = entity.Profesion }; //agregamos el freelancer _dbContext.Add(freelancer); _dbContext.SaveChanges(); FreelancerHability model; //buscamos el ultimo id del freelancer //e iteramos en el listado de habilidades y los vamos agregando a la tabla var id = _dbContext.Freelancers.Max(x => x.Id); foreach (var i in entity.Habilities) { model = new FreelancerHability { FreelancerId = id, HabilityId = i.Id }; _freelancerHabilityService.Add(model); } return(true); } catch (Exception) { return(false); } }
public bool UpdateByFreelancer(UpdateByFreelancerUserVm entity) { try { var model = _dbContext.ApplicationUsers.Single(x => x.Id == entity.Id); model.Avatar = entity.Avatar; model.PhoneNumber = entity.PhoneNumber; _dbContext.Update(model); _dbContext.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public async Task <IActionResult> UploadImg([FromForm] IFormFile file, [FromForm] string id) { if (file != null && id != null) { string avatar = await _imageHandler.UploadImage(file); var model = new UpdateByFreelancerUserVm { Id = id, Avatar = avatar }; return(Ok(_accountService.UpdateByFreelancer(model))); } else { return(BadRequest("Ocurrio un error al cargar la imagen")); } }