//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);
        }
示例#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();
         }
     }
 }
示例#3
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();
            }
        }
示例#4
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();
         }
     }
 }
示例#5
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 ?
     }
 }
示例#6
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);
     }
 }
示例#7
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);
            }
        }
示例#8
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);
     }
 }
        //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);
        }