public string IssueBook(BookHistoryModel obj)
        {
            try
            {
                using (LINQ_to_SQLDataContext dbContext = new LINQ_to_SQLDataContext())
                {
                    if (dbContext.tbl_UserModels.Any(x => x.UserID == obj.UserID && x.IsAdmin == false) && dbContext.tbl_BookModels.Any(x => x.BookID == obj.BookID))
                    {
                        if (dbContext.tbl_BookHistoryModels.Any(x => x.BookID == obj.BookID && x.ReturnedAt == null))
                        {
                            return(StringLiterals.BookIsAssignedToUser);
                        }
                        if (dbContext.tbl_BookModels.Any(x => x.BookID == obj.BookID && (x.IsActive == false || x.IsAvailable == false)))
                        {
                            return(StringLiterals.Error);
                        }
                        dbContext.tbl_BookModels.SingleOrDefault(x => x.BookID == obj.BookID).IsAvailable = false;
                        obj.OperationPerofrmedAt = DateTime.Now;
                        SqlCommand cmd = new SqlCommand("spAddHistory");
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@BookID", obj.BookID);
                        cmd.Parameters.AddWithValue("@UserID", obj.UserID);
                        cmd.Parameters.AddWithValue("@OperationPerformedAt", obj.OperationPerofrmedAt);
                        cmd.Parameters.AddWithValue("@ReturnedAt", System.Data.SqlTypes.SqlDateTime.MinValue);
                        cmd.Parameters.AddWithValue("@Remarks", obj.Remarks);
                        cmd.Parameters.AddWithValue("@PerformedByID", obj.PerformedByID);
                        dbcon.ExeNonQuery(cmd);

                        SqlCommand cmdForLog = new SqlCommand("spAddLog");
                        cmdForLog.CommandType = CommandType.StoredProcedure;
                        cmdForLog.Parameters.AddWithValue("@BookID", obj.BookID);
                        cmdForLog.Parameters.AddWithValue("@UserID", obj.UserID);
                        dbcon.ExeNonQuery(cmdForLog);

                        dbContext.SubmitChanges();
                        return(StringLiterals.IssueBookMsg + (obj.OperationPerofrmedAt.AddDays(30)));
                    }
                    else
                    {
                        return(StringLiterals.Error);
                    }
                }
            }
            catch
            {
                throw;
            }
        }
 public string ReturnBook(int bookID, string remarks)
 {
     using (LINQ_to_SQLDataContext dbContext = new LINQ_to_SQLDataContext())
     {
         if (dbContext.tbl_BookModels.Any(x => x.BookID == bookID && x.IsActive && !x.IsAvailable))
         {
             dbContext.tbl_BookModels.Where(x => x.BookID == bookID).FirstOrDefault().IsAvailable = true;
             dbContext.tbl_BookHistoryModels.OrderByDescending(x => x.BookID == bookID).FirstOrDefault().ReturnedAt = DateTime.Now;
             if (dbContext.tbl_BookHistoryModels.Any(x => x.BookID == bookID && (x.Remarks != remarks || (x.ReturnedAt - x.OperationPerformedAt).TotalDays > 30)))
             {
                 return(StringLiterals.FineMsg);
             }
             dbContext.SubmitChanges();
             return(StringLiterals.ReturnMsg);
         }
         else
         {
             return(StringLiterals.Error);
         }
     }
 }
 public string RemoveUser(int removeID)
 {
     try
     {
         using (LINQ_to_SQLDataContext dbContext = new LINQ_to_SQLDataContext())
         {
             if (dbContext.tbl_UserModels.Any(x => x.UserID == removeID))
             {
                 dbContext.tbl_UserModels.SingleOrDefault(x => x.UserID == removeID).IsActive = false;
                 dbContext.SubmitChanges();
                 return(StringLiterals.RemoveUserMsg);
             }
             else
             {
                 return(StringLiterals.Error);
             }
         }
     }
     catch
     {
         throw;
     }
 }
 public string RemoveBook(int bookID)
 {
     try
     {
         using (LINQ_to_SQLDataContext dbContext = new LINQ_to_SQLDataContext())
         {
             if (dbContext.tbl_BookModels.Any(x => x.BookID == bookID && x.IsActive))
             {
                 dbContext.tbl_BookModels.SingleOrDefault(x => x.BookID == bookID).IsActive    = false;
                 dbContext.tbl_BookModels.SingleOrDefault(x => x.BookID == bookID).IsAvailable = false;
                 dbContext.SubmitChanges();
                 return(StringLiterals.RemoveBookMsg);
             }
             else
             {
                 return(StringLiterals.Error);
             }
         }
     }
     catch
     {
         throw;
     }
 }