Пример #1
0
        //[FromBody]--- form
        //[FromQuery]--- place?city=Seattle&st=wa
        //[FromForm]-- multy-part
        public ActionResult <AdventureImage> Post([FromForm] AdventureImage adventureImage)
        {
            var targetDir = @"C:\dev-project\epicodus_code\CapstoneEpicodus\AdventureBook.Solution\AdventureBook\uploadFiles";

            if (adventureImage.ImgFile.Length > 0)
            {
                //getting login user from session token
                var claimsIdentity = this.User.Identity as ClaimsIdentity;
                var userId         = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
                var user           = adventureDB.Users.FirstOrDefault(entry => entry.Id.ToString() == userId);

                adventureImage.User = user;
                var fileName = Path.GetRandomFileName().Split(".")[0] + Path.GetExtension(adventureImage.ImgFile.FileName);
                var filePath = Path.Combine(targetDir,
                                            fileName);

                using (var stream = System.IO.File.Create(filePath))
                {
                    adventureImage.ImgFile.CopyTo(stream);
                }
                Console.WriteLine("filepath: " + filePath + " length: " + adventureImage.ImgFile.Length);
                adventureImage.ImageUrl = fileName;
            }
            else
            {
                Console.WriteLine("file content zero");
            }

            adventureDB.AdventureImages.Add(adventureImage);
            adventureDB.SaveChanges();
            return(adventureImage);
        }
Пример #2
0
        public void Post([FromBody] ClickCommision clickCommision)

        {
            Campaign campaign = clickComDB.Campaigns.FirstOrDefault(entry => entry.Id == clickCommision.CampaignId);

            clickCommision.Commission = campaign.Commission;
            AdventureImage adventureImage = clickComDB.AdventureImages.FirstOrDefault(entry => entry.Id == clickCommision.AdventureImageId);

            clickCommision.UserId = adventureImage.UserId;
            clickComDB.ClickCommisions.Add(clickCommision);
            clickComDB.SaveChanges();
        }
Пример #3
0
 public void Put(int id, [FromBody] AdventureImage adventureImage)
 {
     adventureImage.Id = id;
     adventureDB.Entry(adventureImage).State = EntityState.Modified;
     adventureDB.SaveChanges();
 }