Example #1
0
        public async Task <UpdateStoryResponse> Handle(UpdateStoryRequest message)
        {
            var story = await _context.Stories.IncludeImages().FirstOrDefaultAsync(s => s.StoryKey == message.StoryKey);

            if (story == null)
            {
                return(new UpdateStoryResponse
                {
                    ErrorType = ErrorType.NotFound
                });
            }

            _context.Entry(story).CurrentValues.SetValues(message);
            _context.Images.RemoveRange(story.Images);
            story.Images.Clear();

            if (message.Images != null)
            {
                var images = message.Images.Select(i => new Image {
                    Base64 = i
                }).ToList();
                _context.Images.AddRange(images);
                story.Images = images;
            }

            return(await _context.TrySaveChangesAsync <UpdateStoryResponse>());
        }
Example #2
0
        public async Task ConsumeAsync(CharityUpdatedEvent message)
        {
            var charityToUpdate = await _context.Charities.FirstOrDefaultAsync(a => a.CharityKey == message.CharityKey);

            if (charityToUpdate != null)
            {
                _context.Entry(charityToUpdate).CurrentValues.SetValues(message);
            }

            await _context.SaveChangesAsync();
        }
        public async Task <IActionResult> Put(int id, [FromBody] Story story)
        {
            if (id != story.Id)
            {
                return(BadRequest("Ids doesn't match"));
            }
            _context.Entry(story).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(Ok());
        }
Example #4
0
 public ActionResult Edit([Bind(Include = "StoryId,CategoryId,AuthorId,Title,Description")] Story story)
 {
     if (ModelState.IsValid)
     {
         db.Entry(story).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AuthorId   = new SelectList(db.Authors, "AuthorId", "FirstName", story.AuthorId);
     ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "Name", story.CategoryId);
     return(View(story));
 }