예제 #1
0
        public async Task <string> Update([FromBody] Book itm)
        {
            /// var OurBook =a_db.Books.Where(z => z.Id == itm.Id).FirstOrDefault();
            var OurBook = _db.Books.Where(z => z.Id == itm.Id).FirstOrDefault();

            if (OurBook == null)
            {
                return("this book is not exist");
            }
            else
            {
                OurBook.Name      = itm.Name;
                OurBook.publisher = itm.publisher;
                OurBook.Title     = itm.Title;
                _db.Books.Update(OurBook);
                _db.SaveChanges();
                return("Upload is Okey ");
            }
        }
        public async Task <IActionResult> Add([FromBody] BookAndShelve item)
        {
            var MyBAndSh = new BookAndShelve
            {
                BookID   = item.BookID,
                ShelveId = item.ShelveId
            };
            var res = await contaxt1.bookAndShelves.AnyAsync(c => c.ShelveId == item.ShelveId);

            if (res)
            {
                return(NotFound());
            }
            else
            {
                contaxt1.bookAndShelves.Add(MyBAndSh);
                contaxt1.SaveChanges();
                return(Ok());
            }
        }
예제 #3
0
        ///for adding shele
        public string Add([FromBody] Shelvecs shelve)
        {
            Shelvecs shelve1 = new Shelvecs
            {
                Name   = shelve.Name,
                Titele = shelve.Titele,
                UserId = shelve.UserId,
                Id     = shelve.Id,
            };
            var res = contaxt1.Shelves.Any(c => c.Id == shelve1.Id);

            if (res)
            {
                return("this shelve is exist later ");
            }
            else
            {
                contaxt1.Shelves.Add(shelve1);
                contaxt1.SaveChanges();
                return("its Okey !!");
            }
        }
예제 #4
0
        /// for deleting the user
        public async Task <string> Delete([FromQuery] string id)
        {
            var ExistUser = await _userManager.FindByNameAsync(id);

            var ExistShelveForUser = await contaxt1.Shelves.Where(z => z.UserId.Equals(ExistUser.Id)).ToListAsync();

            var ids = ExistShelveForUser.Select(x => x.Id).ToList();


            var existShelveandBook = await contaxt1.bookAndShelves.Where(z => ids.Contains(z.ShelveId)).ToListAsync();


            if (ExistUser.Equals(null))
            {
                return(null);
            }
            else
            {
                contaxt1.bookAndShelves.RemoveRange(existShelveandBook);
                contaxt1.Shelves.RemoveRange(ExistShelveForUser);
                IdentityResult result = await _userManager.DeleteAsync(ExistUser);

                contaxt1.SaveChanges();
                if (result.Succeeded)
                {
                    var token = _jWT.Authenticate(ExistUser);
                    if (token == null)
                    {
                        return(null);
                    }
                    return($"30k out, youre token is {token}  ");
                }
                else
                {
                    return("Afrin dabare talash kon ");
                }
            }
            //   IdentityResult result = await _userManager.RemoveLoginAsync(User.Identity.GetUserId(), new UserLoginInfo(loginprovider, providerKey));
        }