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);
            }
        }
 // 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 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);
     }
 }
 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();
     }
 }
Exemplo n.º 6
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);
            }
        }
Exemplo n.º 9
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);
     }
 }
 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);
     }
 }
 //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);
     }
 }
 // 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);
     }
 }
 public bool UpdateAccount(AccountUpdateModel model)
 {
     using (var context = new HallAutomationSystemEntities())
     {
         AddressInformation addressInformation = new AddressInformation();
         int id      = addressInformation.GetStudentId(model.UserName);
         var account = context.Account.FirstOrDefault(x => x.StudentId == id);
         if (account != null)
         {
             if (account.Due > 0)
             {
                 int minus = Math.Min((int)account.Due, (int)model.Balance);
                 model.Balance -= minus;
                 account.Due   -= minus;
             }
             account.Balance += model.Balance;
         }
         context.SaveChanges();
         return(true);
     }
 }