//adding edited user Info
        public int editUserInfo(UserInfo userDetails)
        {
            int userID = 0;

            using (var context = new BbmDBEntities())
            {
                var userToEdit = from ser in context.Users
                                 where ser.UId == userDetails.UId &&
                                 ser.Name == userDetails.Name &&
                                 ser.UserRole == userDetails.UserRole
                                 select ser;
                {
                    foreach (var item in userToEdit)
                    {
                        item.AddressId = userDetails.AddressId;
                        item.Age       = userDetails.Age;
                        item.BloodId   = userDetails.BloodId;
                        item.Name      = userDetails.Name;
                        item.Email     = userDetails.Email;
                        item.Phone     = userDetails.Phone;
                        item.Password  = userDetails.Password;
                        item.UserRole  = userDetails.UserRole;
                        item.Date      = DateTime.Now;
                        userID         = item.UId;
                    }
                    context.SaveChanges();
                }
            }
            return(userID);
        }
Exemple #2
0
 //remove from inventory if BI_Quantity = 0
 private void RemoveFromInventory(int inventoryId)
 {
     using (var context = new BbmDBEntities())
     {
         var itemToRemove = context.BloodInventories.SingleOrDefault(x => x.BInventory_Id == inventoryId);
         if (itemToRemove != null)
         {
             context.BloodInventories.Remove(itemToRemove);
             context.SaveChanges();
         }
     }
 }
Exemple #3
0
 public System.Collections.IEnumerable Blood()
 {
     using (var context = new BbmDBEntities())
     {
         var bloodStat = from ins in context.BloodDatas
                         select new
         {
             SN         = ins.BId,
             BloodGroup = ins.Title,
             Available  = ins.AvailableQuantity,
             Capacity   = ins.TotalCapacity
         };
         return(bloodStat.ToList());
     }
 }
 public AddressInfo InitializeUserAddress(AddressInfo addressDetails)
 {
     using (var context = new BbmDBEntities())
     {
         var addressToEdit = context.Addresses.SingleOrDefault(x => x.AId == addressDetails.AId);
         addressDetails.AId         = addressToEdit.AId;
         addressDetails.Houseno     = addressToEdit.Houseno;
         addressDetails.Roadno      = addressToEdit.Roadno;
         addressDetails.SubDistrict = addressToEdit.SubDistrict;
         addressDetails.District    = addressToEdit.District;
         addressDetails.Zip         = addressToEdit.Zip;
         addressDetails.Country     = addressToEdit.Country;
     }
     return(addressDetails);
 }
Exemple #5
0
        //donation request, Updating BloodData table
        public void AddtoBloodData(RequestInfo request)
        {
            int newQuantity = 0;

            using (var context = new BbmDBEntities())
            {
                var bloodDataToUpdate = from blood in context.BloodDatas where blood.Title == request.BloodID select blood;
                foreach (var item in bloodDataToUpdate)
                {
                    newQuantity            = item.AvailableQuantity;
                    newQuantity            = newQuantity + request.Quantity;
                    item.AvailableQuantity = newQuantity;
                }
                context.SaveChanges();
            }
        }
Exemple #6
0
 //update inventory if BI_Quantity > 0
 private void UpdateInventory(int inventoryId, int quantity)
 {
     using (var context = new BbmDBEntities())
     {
         var itemToRemove = from bloodInventoy in context.BloodInventories
                            where bloodInventoy.BInventory_Id == inventoryId
                            select bloodInventoy;
         if (itemToRemove != null)
         {
             foreach (var item in itemToRemove)
             {
                 item.BI_Quantity = item.BI_Quantity - quantity;
             }
             context.SaveChanges();
         }
     }
 }
Exemple #7
0
 //user Login Starts here
 public UserInfo UserLogin(string userName, string password, UserInfo loggedInUserInfo)
 {
     using (var context = new BbmDBEntities())
     {
         var userToLogin = from person in context.Users where (person.Name == userName) && (person.Password == password) select person;
         if (userToLogin.Count() != 0)
         {
             foreach (var item in userToLogin)
             {
                 loggedInUserInfo.UId      = item.UId;
                 loggedInUserInfo.UserRole = item.UserRole;
                 loggedInUserInfo.Name     = item.Name;
             }
         }
     }
     return(loggedInUserInfo);
 }
Exemple #8
0
 public int AddUserAddress(AddressInfo addressDetails) //to add addRess
 {
     using (var context = new BbmDBEntities())
     {
         var newAddress = new Address //creating new addRess and inserting
         {
             Houseno     = addressDetails.Houseno,
             Roadno      = addressDetails.Roadno,
             SubDistrict = addressDetails.SubDistrict,
             District    = addressDetails.District,
             Country     = addressDetails.Country,
             Zip         = addressDetails.Zip
         };
         context.Addresses.Add(newAddress);
         context.SaveChanges();
         return(newAddress.AId);
     }
 }
 //load inventory data by Blood_group
 public System.Collections.IEnumerable InventoryDataByBloodGroup(string bloodGroup)
 {
     using (var context = new BbmDBEntities())
     {
         var inventoryInstance =
             from ins in context.BloodInventories where ins.Blood_Group == bloodGroup
             select new
         {
             ID          = ins.BInventory_Id,
             UserID      = ins.BI_UserId,
             Blood_Group = ins.Blood_Group,
             Quantity    = ins.BI_Quantity,
             Bag_Code    = ins.BI_Bag_Code,
             Date        = ins.BI_Date
         };
         return(inventoryInstance.ToList());
     }
 }
Exemple #10
0
 //donation request adding to history
 public void AddToHistory(RequestInfo request, string bagCode)
 {
     using (var context = new BbmDBEntities())
     {
         var HistoryToAdd = new History()
         {
             UserId           = request.UserID,
             UserName         = request.UserName,
             RequestType      = request.RequestTypeID,
             BloodGroup       = request.BloodID,
             Quantity         = request.Quantity,
             History_Bag_Code = bagCode,
             History_date     = DateTime.Now
         };
         context.Histories.Add(HistoryToAdd);
         context.SaveChanges();//error because if blood not found what is the bag code ?
     }
 }
Exemple #11
0
        //*****Donation******//



        //*****Obtain******//
        //Main Blood inventory check for total quantity availability
        public bool BloodAvailability(RequestInfo request)
        {
            using (var context = new BbmDBEntities())
            {
                var bloodData = from blood in context.BloodDatas
                                where blood.Title == request.BloodID &&
                                blood.AvailableQuantity >= request.Quantity
                                select blood;

                if (bloodData.Count() != 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Exemple #12
0
        //*****Donation******//
        //donation request adding to inventory
        public string AddToInventory(RequestInfo request)
        {
            string _randomString = RandomString(4);

            using (var context = new BbmDBEntities())
            {
                var newInventoryEntry = new BloodInventory()
                {
                    BI_UserId   = request.UserID,
                    Blood_Group = request.BloodID,
                    BI_Quantity = request.Quantity,
                    BI_Bag_Code = request.UserID + _randomString,
                    BI_Date     = DateTime.Now
                };
                context.BloodInventories.Add(newInventoryEntry);//if i do single for each quantiy then it will consume more data
                context.SaveChanges();
                return(newInventoryEntry.BI_Bag_Code);
            }
        }
        //public static UserInfo userDetails = new UserInfo();
        //public static UserInfo addressDetails = new UserInfo();

        public UserInfo InitializeUserInfo(UserInfo userDetails)
        {
            using (var context = new BbmDBEntities())
            {
                var userToEdit = context.Users.SingleOrDefault(x => x.UId == userDetails.UId);
                {
                    userDetails.UId        = userToEdit.UId;
                    userDetails.AddressId  = userToEdit.AddressId;
                    userDetails.UserRole   = userToEdit.UserRole;
                    userDetails.Name       = userToEdit.Name;
                    userDetails.Email      = userToEdit.Email;
                    userDetails.Password   = userToEdit.Password;
                    userDetails.Phone      = userToEdit.Phone;
                    userDetails.BloodId    = userToEdit.BloodId;
                    userDetails.BloodGroup = userToEdit.BloodData.Title;
                    userDetails.Age        = userToEdit.Age;
                }
            }
            return(userDetails);
        }
 //all history for admin->ReportForm
 public System.Collections.IEnumerable ExchangeHistory()
 {
     using (var context = new BbmDBEntities())
     {
         var HistoryInstance =
             from ins in context.Histories
             select new
         {
             // SN = ins.HId,
             ID          = ins.UserId,
             Name        = ins.UserName,
             Request     = ins.RequestType,
             Blood_Group = ins.BloodGroup,
             Quantity    = ins.Quantity,
             Bag_Code    = ins.History_Bag_Code,
             Date        = ins.History_date
         };
         return(HistoryInstance.ToList());
     }
 }
Exemple #15
0
 public int AddUser(UserInfo userDetails)//to add new User
 {
     using (var context = new BbmDBEntities())
     {
         var newUser = new User //creating new user for insertion
         {
             Name      = userDetails.Name,
             Phone     = userDetails.Phone,
             Email     = userDetails.Email,
             Age       = userDetails.Age,
             AddressId = userDetails.AddressId,
             BloodId   = userDetails.BloodId,
             UserRole  = userDetails.UserRole,
             Password  = userDetails.Password,
             Date      = DateTime.Now
         };
         context.Users.Add(newUser);
         context.SaveChanges();//causing error
         return(newUser.UId);
     }
 }
Exemple #16
0
        //Obtain request,returning bagcode Inventory check
        public string RequestBagCode(RequestInfo request)
        {
            int    totalQuantity = 0;
            int    individualInventoryQuantity = 0;
            string bagCode = null;

            using (var context = new BbmDBEntities())
            {
                var selectRowToGetData = from blood in context.BloodInventories
                                         where blood.Blood_Group == request.BloodID
                                         select blood;


                foreach (var item in selectRowToGetData)
                {
                    while (totalQuantity < request.Quantity)
                    {
                        totalQuantity++;

                        item.BI_Quantity--;
                        individualInventoryQuantity++;
                        bagCode = item.BI_Bag_Code + " " + bagCode;

                        if (item.BI_Quantity == 0)
                        {
                            RemoveFromInventory(item.BInventory_Id);
                            individualInventoryQuantity = 0;
                            break;
                        }
                        if (totalQuantity == request.Quantity && item.BI_Quantity > 0)
                        {
                            UpdateInventory(item.BInventory_Id, individualInventoryQuantity);
                            individualInventoryQuantity = 0;
                            break;
                        }
                    }
                }
            }
            return(bagCode);
        }
        //adding edited user address
        public int editUserAddress(AddressInfo addressDetails)
        {
            int addressID = 0;

            using (var context = new BbmDBEntities())
            {
                var editAddress = from addressToEdit in context.Addresses
                                  where addressToEdit.AId == addressDetails.AId
                                  select addressToEdit;
                foreach (var item in editAddress)
                {
                    item.Houseno     = addressDetails.Houseno;
                    item.Roadno      = addressDetails.Roadno;
                    item.SubDistrict = addressDetails.SubDistrict;
                    item.District    = addressDetails.District;
                    item.Country     = addressDetails.Country;
                    item.Zip         = addressDetails.Zip;
                    addressID        = item.AId;
                }
                context.SaveChanges();
            }
            return(addressID);
        }