public ActionResult Create(BrotherResponse brother)
        {
            if (ModelState.IsValid)
            {
                var client  = new RestClient();
                var request = new RestRequest("http://localhost:5003/api/brothers", DataFormat.Json);
                request.AddJsonBody(brother);
                var response = client.Post <Brother>(request);

                return(Redirect("/friend/index"));
            }
            return(BadRequest());
        }
Пример #2
0
        public async Task <ActionResult <Brother> > PostBrother(BrotherResponse brotherResponse)
        {
            var friendTake = await _context.Friends.FirstOrDefaultAsync(z => z.Id == brotherResponse.Friend.Id);

            brotherResponse.Friend = friendTake;
            Brother brother = new Brother {
                Name = brotherResponse.Name, Surname = brotherResponse.Surname, Email = brotherResponse.Email, Telephone = brotherResponse.Telephone, Friend = brotherResponse.Friend
            };

            _context.Brothers.Add(brother);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetBrother", new { id = brother.Id }, brother));
        }