public async Task <IActionResult> PostnewUser(IFormFile file, [FromForm] string jsonData) { // var content = new homeContent(); // List<homeContent> content = homeContent content = JsonConvert.DeserializeObject <homeContent>(jsonData); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var coinData = new greenCoins(); var imageResponse = await AmazonS3Service.UploadObject(file); //promiseAll var data = this.HttpContext.Items["User"].ToString(); long id = long.Parse(data); var newUser = _repo.Profile.FirstOrDefault(u => u.id == id); var now = DateTime.UtcNow; content.profileid = id; content.profilename = newUser.firstname; content.profilemedia = newUser.profilemedia; content.createdAt = now; content.updatedAt = now; content.createdBy = newUser.firstname; content.updatedBy = newUser.firstname; content.url = imageResponse.FileName; _repo.Add(content); _repo.SaveChanges(); Random rnd = new Random(); int coin = rnd.Next(1, 11); //random value between 1-10 coinData.profileid = id; coinData.postid = content.id; coinData.createdAt = now; coinData.createdBy = newUser.firstname; coinData.coins = coin; //make it random 1-10 //orderby with linkq //descending _repo.Add(coinData); _repo.SaveChanges(); return(Ok(coinData)); } catch (Exception ex) { return(BadRequest(ex)); } }
public async Task <IActionResult> CreateClothings([FromForm] string name, [FromForm] int idClothingType, [FromForm] string tags, IFormFile image) { var imageResponse = await AmazonS3Service.UploadObject(image); var idUser = User.FindFirstValue(ClaimTypes.NameIdentifier); CreateClothesCommand command = new CreateClothesCommand() { Name = name, idUser = Int32.Parse(idUser), Url = imageResponse.FileName, idClothingType = idClothingType, Tags = tags }; var commandResult = await _mediator.Send(command); return(Ok(commandResult)); }