public int AddAddress(AddressModel model, string UserName)
 {
     using (var context = new HallAutomationSystemEntities())
     {
         int DistId1 = GetDistrictId(model.Permanent_District_Name);
         int DistId2 = GetDistrictId(model.Temporary_District_Name);
         if (DistId1 == 0 || DistId2 == 0)
         {
             return(0);
         }
         Address address = new Address()
         {
             P_DistrictId  = DistId1,
             T_DistrictId  = DistId2,
             P_VillageName = model.Permanent_Village_Name,
             P_PostOffice  = model.Permanent_Post_Office,
             T_VillageName = model.Temporary_Village_Name,
             T_PostOffice  = model.Temporary_Post_Office,
             StudentId     = GetStudentId(UserName)
         };
         context.Address.Add(address);
         context.SaveChanges();
         return(address.StudentId);
     }
 }
 // To Add The User Personal Information into Student Table
 public int AddStudentPersonalInfo(StudentModel model, string UserName)
 {
     using (var context = new HallAutomationSystemEntities())
     {
         int RoomId = GetRoomId(model.RoomNumber);
         if (RoomId == 0) /// If Room Number is not valid
         {
             return(0);
         }
         RoomInformation roomInformation = new RoomInformation();
         roomInformation.UpdateRoom(RoomId, -1);
         Student student = new Student()
         {
             StudentName  = model.StudentName,
             FatherName   = model.FatherName,
             MotherName   = model.MotherName,
             MobileNumber = model.MobileNumber,
             RoomId       = RoomId,
             UserId       = GetUserId(UserName)
         };
         context.Student.Add(student);
         context.SaveChanges();
         AccountInformation accountInformation = new AccountInformation();
         accountInformation.AddAccount(UserName, student.StudentId);
         return(student.StudentId);
     }
 }
        public int UpdateMeal(MealUpdateModel model)
        {
            using (var context = new HallAutomationSystemEntities())
            {
                var meal = context.Meal.FirstOrDefault(x => x.MealId == model.MealId && x.Date == DateTime.Today);
                if (meal == null)
                {
                    return(-3);
                }
                TimeSpan now   = DateTime.Now.TimeOfDay;
                TimeSpan start = new TimeSpan(00, 0, 0);
                TimeSpan End   = new TimeSpan(24, 00, 0);
                if (!(now >= start && now <= End))
                {
                    return(-1);
                }

                int taka      = searchOperation.GetMealCost();
                int meal_cost = (meal.Dinnar * taka + meal.Lunch * taka);
                accountInformation.decreamentAccountBalance((int)meal.StudentId, (-1) * meal_cost);
                int     New_Meal_Cost = (model.Dinnar * taka + model.Lunch * taka);
                Account account       = searchOperation.GetAccount((int)meal.StudentId);
                if (New_Meal_Cost > account.Balance)
                {
                    return(-2);
                }
                meal.Lunch  = model.Lunch;
                meal.Dinnar = model.Dinnar;
                context.SaveChanges();
                return(meal.MealId);
            }
        }
Exemple #4
0
 public List <Meal> GetAllMeals()
 {
     using (var context = new HallAutomationSystemEntities())
     {
         var mealList = context.Meal.Where(x => x.Date == DateTime.Today).ToList();
         return(mealList);
     }
 }
 public void UpdateRoom(int RoomNumber, int flag)
 {
     using (var context = new HallAutomationSystemEntities())
     {
         var room = context.Rooms.FirstOrDefault(x => x.RoomId == RoomNumber);
         if (room != null)
         {
             room.EmptySeat = room.EmptySeat + flag;
         }
         context.SaveChanges();
     }
 }
 public void decreamentAccountBalance(int StudentId, int taka)
 {
     using (var context = new HallAutomationSystemEntities())
     {
         var account = context.Account.FirstOrDefault(x => x.StudentId == StudentId);
         if (account != null)
         {
             account.Balance -= taka;
         }
         context.SaveChanges();
     }
 }
Exemple #7
0
 public int AddDistrict(DistrictModel model)
 {
     using (var context = new HallAutomationSystemEntities())
     {
         District district = new District()
         {
             DistrictName = model.DistrictName
         };
         context.District.Add(district);
         context.SaveChanges();
         return(district.DistrictId);
     }
 }
        public int AddMeal(MealModel model, string UserName)
        {
            var user    = searchOperation.GetUser(UserName);
            var student = searchOperation.GetStudent(user.UserId);
            var room    = searchOperation.GetRoom((int)student.RoomId);

            using (var context = new HallAutomationSystemEntities())
            {
                var meal = context.Meal.FirstOrDefault(x => x.StudentId == student.StudentId);
                if (meal != null)
                {
                    return(-3);
                }
            }
            TimeSpan now   = DateTime.Now.TimeOfDay;
            TimeSpan start = new TimeSpan(00, 0, 0);
            TimeSpan End   = new TimeSpan(24, 00, 0);

            if (!(now >= start && now <= End))
            {
                return(-1);
            }
            Account account   = searchOperation.GetAccount(student.StudentId);
            int     taka      = searchOperation.GetMealCost();
            int     meal_cost = (model.Dinnar * taka + model.Lunch * taka);

            if (meal_cost > account.Balance)
            {
                return(-2);
            }
            else
            {
                accountInformation.decreamentAccountBalance(student.StudentId, meal_cost);
            }
            using (var context = new HallAutomationSystemEntities())
            {
                Meal meal = new Meal()
                {
                    StudentId   = student.StudentId,
                    RoomNo      = room.RoomNumber,
                    Dinnar      = model.Dinnar,
                    Lunch       = model.Lunch,
                    Time        = DateTime.Now.TimeOfDay,
                    Date        = DateTime.Today,
                    StudentName = student.StudentName
                };
                context.Meal.Add(meal);
                context.SaveChanges();
                return(meal.MealId);
            }
        }
        public int AddDepartmentName(DepartmentModel model)
        {
            using (var context = new HallAutomationSystemEntities())
            {
                Department department = new Department()
                {
                    DeptName = model.DepartmentName
                };

                context.Department.Add(department);
                context.SaveChanges();
                return(department.DeptId);
            }
        }
Exemple #10
0
 public int GetMealCost(int id = 1)
 {
     using (var context = new HallAutomationSystemEntities())
     {
         var mealcost = context.MealCost.FirstOrDefault(x => x.MealCostId == id);
         if (mealcost != null)
         {
             return(mealcost.MealCost1);
         }
         else
         {
             return(-1);
         }
     }
 }
 public int AddAccount(string UserName, int StudentId)
 {
     using (var context = new HallAutomationSystemEntities())
     {
         Account account = new Account()
         {
             StudentId = StudentId,
             Balance   = 0,
             Due       = 0
         };
         context.Account.Add(account);
         context.SaveChanges();
         return(account.StudentId);
     }
 }
Exemple #12
0
 public int Operation(RegistrationModel model)
 {
     using (var context = new HallAutomationSystemEntities())
     {
         Users user = new Users()
         {
             UserName  = model.UserName,
             UserEmail = model.UserEmail,
             Password  = HashFunction(model.Password)
         };
         context.Users.Add(user);
         context.SaveChanges();
         return(user.UserId);
     }
 }
 //To add room information
 public int AddRoom(RoomModel model)
 {
     using (var context = new HallAutomationSystemEntities())
     {
         Room room = new Room()
         {
             RoomNumber = model.RoomNumber,
             TotalSeat  = model.TotalSeat,
             EmptySeat  = model.EmptySeat
         };
         context.Rooms.Add(room);
         context.SaveChanges();
         return(room.RoomId);
     }
 }
 // To get the Room Id by using Room Number.
 public int GetRoomId(int RoomNumber)
 {
     using (var context = new HallAutomationSystemEntities())
     {
         var room = context.Rooms.FirstOrDefault(x => x.RoomNumber == RoomNumber);
         if (room != null)
         {
             return(room.RoomId);
         }
         else
         {
             return(0);
         }
     }
 }
 public int GetDepartmentId(string DeptName)
 {
     using (var context = new HallAutomationSystemEntities())
     {
         var department = context.Department.FirstOrDefault(x => x.DeptName == DeptName);
         if (department != null)
         {
             return(department.DeptId);
         }
         else
         {
             return(0);
         }
     }
 }
 // To get the User Id by using User Name from Session
 public int GetUserId(string UserName)
 {
     using (var context = new HallAutomationSystemEntities())
     {
         var user = context.Users.FirstOrDefault(x => x.UserName == UserName);
         if (user != null)
         {
             return(user.UserId);
         }
         else
         {
             return(0);
         }
     }
 }
 /// <summary>
 /// To Get District Id by Using District Name
 /// </summary>
 /// <param name="DistrictName"></param>
 /// <returns>District Id</returns>
 public int GetDistrictId(string DistrictName)
 {
     using (var context = new HallAutomationSystemEntities())
     {
         var district = context.District.FirstOrDefault(x => x.DistrictName == DistrictName);
         if (district != null)
         {
             return(district.DistrictId);
         }
         else
         {
             return(0);
         }
     }
 }
Exemple #18
0
 // Get a row from meal table by using StudentId
 public Meal GetMeal(int StudentId)
 {
     using (var context = new HallAutomationSystemEntities())
     {
         var meal = context.Meal.FirstOrDefault(x => x.StudentId == StudentId && x.Date == DateTime.Today);
         if (meal != null)
         {
             return(meal);
         }
         else
         {
             //meal.StudentId = -1;
             return(meal);
         }
     }
 }
Exemple #19
0
 // Get a row from Department table by using DepartmentId
 public Department GetDepartment(int DepartmentId)
 {
     using (var context = new HallAutomationSystemEntities())
     {
         var department = context.Department.FirstOrDefault(x => x.DeptId == DepartmentId);
         if (department != null)
         {
             return(department);
         }
         else
         {
             //department.DeptId = -1;
             return(department);
         }
     }
 }
Exemple #20
0
 public bool LoginOperation(LoginModel model)
 {
     using (var context = new HallAutomationSystemEntities())
     {
         var user     = context.Users.FirstOrDefault(x => x.UserName == model.UserName);
         int password = emp.HashFunction(model.Password);
         if (password == user.Password)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Exemple #21
0
 public Account GetAccount(int StudentId)
 {
     using (var context = new HallAutomationSystemEntities())
     {
         var account = context.Account.FirstOrDefault(x => x.StudentId == StudentId);
         if (account != null)
         {
             return(account);
         }
         else
         {
             //meal.StudentId = -1;
             return(account);
         }
     }
 }
Exemple #22
0
 // Get a row from Student table by using UserId
 public Student GetStudent(int UserId)
 {
     using (var context = new HallAutomationSystemEntities())
     {
         var student = context.Student.FirstOrDefault(x => x.UserId == UserId);
         if (student != null)
         {
             return(student);
         }
         else
         {
             //student.StudentId = -1;
             return(student);
         }
     }
 }
Exemple #23
0
 // Get a row from Address table by using StudentId
 public Address GetAddress(int StudentId)
 {
     using (var context = new HallAutomationSystemEntities())
     {
         var address = context.Address.FirstOrDefault(x => x.StudentId == StudentId);
         if (address != null)
         {
             return(address);
         }
         else
         {
             //address.StudentId = -1;
             return(address);
         }
     }
 }
Exemple #24
0
 // Get a row from Room table by using RoomId
 public Room GetRoom(int RoomId)
 {
     using (var context = new HallAutomationSystemEntities())
     {
         var room = context.Rooms.FirstOrDefault(x => x.RoomId == RoomId);
         if (room != null)
         {
             return(room);
         }
         else
         {
             //room.RoomId = -1;
             return(room);
         }
     }
 }
Exemple #25
0
 // Get a row from DepartmentInfo table by using StudentId
 public DepartmentInfo GetDepartmentInfo(int StudentId)
 {
     using (var context = new HallAutomationSystemEntities())
     {
         var departmentinfo = context.DepartmentInfo.FirstOrDefault(x => x.StudentId == StudentId);
         if (departmentinfo != null)
         {
             return(departmentinfo);
         }
         else
         {
             //departmentinfo.DepartmentId = -1;
             return(departmentinfo);
         }
     }
 }
Exemple #26
0
 // Get a row from District Table by using District Id
 public District GetDistrict(int Districtid)
 {
     using (var context = new HallAutomationSystemEntities())
     {
         var district = context.District.FirstOrDefault(x => x.DistrictId == Districtid);
         if (district != null)
         {
             return(district);
         }
         else
         {
             //district.DistrictId = -1;
             return(district);
         }
     }
 }
 //Address Update from UpdateController
 public bool UpdateAddress(AdressUpdateModel model)
 {
     using (var context = new HallAutomationSystemEntities())
     {
         var address = context.Address.FirstOrDefault(x => x.StudentId == model.StudentId);
         if (address != null)
         {
             address.P_DistrictId  = GetDistrictId(model.Permanent_District_Name);
             address.P_PostOffice  = model.Permanent_Post_Office;
             address.P_VillageName = model.Permanent_Village_Name;
             address.T_DistrictId  = GetDistrictId(model.Temporary_District_Name);
             address.T_PostOffice  = model.Temporary_Post_Office;
             address.T_VillageName = model.Temporary_Village_Name;
         }
         context.SaveChanges();
         return(true);
     }
 }
        public int GetStudentId(string UserName)
        {
            StudentInformation temp = new StudentInformation();
            int UserId = temp.GetUserId(UserName);

            using (var context = new HallAutomationSystemEntities())
            {
                var student = context.Student.FirstOrDefault(x => x.UserId == UserId);
                if (student != null)
                {
                    return(student.StudentId);
                }
                else
                {
                    return(0);
                }
            }
        }
 // Student data update from UpdateController
 public bool UpdateStudent(StudentUpdateModel model)
 {
     using (var context = new HallAutomationSystemEntities())
     {
         var             student         = context.Student.FirstOrDefault(x => x.StudentId == model.StudentId);
         RoomInformation roomInformation = new RoomInformation();
         roomInformation.UpdateRoom((int)student.RoomId, 1);
         if (student != null)
         {
             student.StudentName  = model.StudentName;
             student.FatherName   = model.FatherName;
             student.MotherName   = model.MotherName;
             student.MobileNumber = model.MobileNumber;
             student.RoomId       = (int)GetRoomId(model.RoomNumber);
         }
         roomInformation.UpdateRoom((int)student.RoomId, -1);
         context.SaveChanges();
         return(true);
     }
 }
 public int AddStudentDepartmentInformation(StudentDepartmentInformationModel model, string UserName)
 {
     using (var context = new HallAutomationSystemEntities())
     {
         int Dept_Name = GetDepartmentId(model.Department_name);
         if (Dept_Name == 0)
         {
             return(0);
         }
         DepartmentInfo departmentInfo = new DepartmentInfo()
         {
             DepartmentId = Dept_Name,
             StudentId    = GetStudentId(UserName),
             Session      = model.Session,
             Cgpa         = model.Cgpa
         };
         context.DepartmentInfo.Add(departmentInfo);
         context.SaveChanges();
         return(departmentInfo.StudentId);
     }
 }