Пример #1
0
        public async Task <IdentityResult> UpdateFriendAsync(Domain.Friend.Friend newFriend)
        {
            var oldFriend = Context.Friends.FirstOrDefault(x => x.Id == newFriend.Id);

            oldFriend.Name = newFriend.Name;
            using (var transaction = this.Context.Database.BeginTransaction())
            {
                try
                {
                    foreach (var item in oldFriend.Friends)
                    {
                        item.Friend     = oldFriend;
                        item.FriendName = oldFriend.Name;
                        this.Context.FriendFriends.Update(item);
                    }
                    await this.Context.SaveChangesAsync();

                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                    transaction.Rollback();
                }
            }
            Context.Friends.Update(oldFriend);
            await this.Context.SaveChangesAsync();

            return(IdentityResult.Success);
        }
Пример #2
0
        public async Task <IdentityResult> CreateFriendAsync(Domain.Friend.Friend friend)
        {
            this.Context.Friends.Add(friend);
            await this.Context.SaveChangesAsync();

            return(IdentityResult.Success);
        }
Пример #3
0
        public async Task <ActionResult> Edit(Domain.Friend.Friend friend)
        {
            try
            {
                var client = new RestClient();
                var id     = JsonConvert.DeserializeObject(this.HttpContext.Session.GetString("FriendId"));

                var requestFriend = new RestRequest("https://localhost:5003/api/friend/edit/");
                requestFriend.AddJsonBody(JsonConvert.SerializeObject(new
                {
                    Id   = id,
                    Name = friend.Name
                }));

                await client.PutAsync <Domain.Friend.Friend>(requestFriend);

                this.HttpContext.Session.Remove("FriendId");

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                ModelState.AddModelError("APP_ERROR", "Friend doesn't exist.");
                return(View());
            }
        }
Пример #4
0
 public async Task <IdentityResult> UpdateFriendAsync(Domain.Friend.Friend newFriend)
 {
     if (this.FriendRepository.GetAll().Where(x => x.Id == newFriend.Id).FirstOrDefault() == null)
     {
         throw new Exception("Friend doesn't exists.");
     }
     return(await FriendRepository.UpdateFriendAsync(newFriend));
 }
Пример #5
0
 public async Task <IdentityResult> CreateFriendAsync(Domain.Friend.Friend friend)
 {
     return(await FriendRepository.CreateFriendAsync(friend));
 }
Пример #6
0
 public async Task <IdentityResult> Put([FromBody] Domain.Friend.Friend friend)
 {
     return(await this.FriendService.UpdateFriendAsync(friend));
 }