コード例 #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            SchoolBranch schoolBranch = db.SchoolBranches.Find(id);

            db.SchoolBranches.Remove(schoolBranch);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #2
0
 public bool Create(Branch entity, int?countryId, int?stateId, int?cityId, int SchoolId)
 {
     using (var context = new CourseContext())
     {
         Branch branch = entity;
         if (countryId != null)
         {
             Country country = context.Country.Find(countryId);
             if (country != null)
             {
                 BranchCountry branchCountry = new BranchCountry()
                 {
                     Branch = branch, Country = country
                 };
                 context.Add(branchCountry);
             }
         }
         if (stateId != null)
         {
             State state = context.State.Find(stateId);
             if (state != null)
             {
                 BranchState branchState = new BranchState()
                 {
                     Branch = branch, State = state
                 };
                 context.Add(branchState);
             }
         }
         if (cityId != null)
         {
             City city = context.City.Find(cityId);
             if (city != null)
             {
                 BranchCity branchCity = new BranchCity()
                 {
                     Branch = branch, City = city
                 };
                 context.Add(branchCity);
             }
         }
         School school = context.School.Find(SchoolId);
         if (school != null)
         {
             SchoolBranch schoolBranch = new SchoolBranch()
             {
                 School = school, Branch = branch
             };
             context.Add(schoolBranch);
         }
         context.SaveChanges();
         return(true);
     }
 }
コード例 #3
0
 public ActionResult Edit([Bind(Include = "Id,Name,Address,SchoolId,Contact_Detail,Branch_Code")] SchoolBranch schoolBranch)
 {
     if (ModelState.IsValid)
     {
         db.Entry(schoolBranch).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.SchoolId = new SelectList(db.Schools, "Id", "Name", schoolBranch.SchoolId);
     return(View(schoolBranch));
 }
コード例 #4
0
        public bool InsertSchool(string name, string phone, string address, string latitude, string longitude, int districtId, int insId, int updId)
        {
            try
            {
                School school = new School();
                school.Name        = name;
                school.DelFlg      = false;
                school.Ver         = 1;
                school.InsId       = insId;
                school.InsDateTime = DateTime.Now;
                school.UpdId       = updId;
                school.UpdDateTime = DateTime.Now;
                db.School.Add(school);

                Location location = new Location();
                location.StreetAddress = address;
                location.Latitude      = latitude;
                location.Longitude     = longitude;
                location.DistrictId    = districtId;
                location.DelFlg        = false;
                location.Ver           = 1;
                location.InsId         = insId;
                location.InsDateTime   = DateTime.Now;
                location.UpdId         = updId;
                location.UpdDateTime   = DateTime.Now;
                db.Location.Add(location);


                int          lastId       = db.School.OrderByDescending(x => x.Id).FirstOrDefault().Id;
                int          lastLocation = db.Location.OrderByDescending(x => x.Id).FirstOrDefault().Id;
                SchoolBranch schoolBranch = new SchoolBranch();
                schoolBranch.SchoolId    = lastId + 1;
                schoolBranch.LocationId  = lastLocation + 1;
                schoolBranch.Phone       = phone;
                schoolBranch.DelFlg      = false;
                schoolBranch.Ver         = 1;
                schoolBranch.InsId       = insId;
                schoolBranch.InsDateTime = DateTime.Now;
                schoolBranch.UpdId       = updId;
                schoolBranch.UpdDateTime = DateTime.Now;
                db.SchoolBranch.Add(schoolBranch);


                db.SaveChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
コード例 #5
0
        // GET: SchoolBranches/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SchoolBranch schoolBranch = db.SchoolBranches.Find(id);

            if (schoolBranch == null)
            {
                return(HttpNotFound());
            }
            return(View(schoolBranch));
        }
コード例 #6
0
        public bool UpdateSchool(int id, string phone, string address, string latitude, string longitude, int districtId, int updId)
        {
            try
            {
                SchoolBranch schoolBranch = db.SchoolBranch.FirstOrDefault(x => x.Id == id);
                Location     location     = db.Location.FirstOrDefault(x => x.Id == schoolBranch.LocationId);
                if (schoolBranch == null)
                {
                    return(false);
                }

                if (phone != null)
                {
                    schoolBranch.Phone = phone;
                }
                if (address != null)
                {
                    location.StreetAddress = address;
                }
                if (latitude != null)
                {
                    location.Latitude = latitude;
                }
                if (longitude != null)
                {
                    location.Longitude = longitude;
                }
                if (districtId.ToString() != null)
                {
                    location.DistrictId = districtId;
                }


                schoolBranch.Ver         = schoolBranch.Ver + 1;
                schoolBranch.UpdDateTime = DateTime.Now;
                schoolBranch.Ver         = schoolBranch.Ver + 1;
                schoolBranch.UpdDateTime = DateTime.Now;
                location.Ver             = location.Ver + 1;
                location.UpdDateTime     = DateTime.Now;
                db.Location.Update(location);
                db.SchoolBranch.Update(schoolBranch);

                db.SaveChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
コード例 #7
0
        // GET: SchoolBranches/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SchoolBranch schoolBranch = db.SchoolBranches.Find(id);

            if (schoolBranch == null)
            {
                return(HttpNotFound());
            }
            ViewBag.SchoolId = new SelectList(db.Schools, "Id", "Name", schoolBranch.SchoolId);
            return(View(schoolBranch));
        }
コード例 #8
0
        public bool DeleteSchool(int id)
        {
            SchoolBranch schoolBranch = db.SchoolBranch.FirstOrDefault(x => x.Id == id);
            Location     location     = db.Location.FirstOrDefault(x => x.Id == schoolBranch.LocationId);

            if (schoolBranch == null)
            {
                return(false);
            }
            schoolBranch.DelFlg = true;
            location.DelFlg     = true;
            db.SchoolBranch.Update(schoolBranch);
            db.Location.Update(location);
            db.SaveChanges();
            return(true);
        }
コード例 #9
0
ファイル: AuthRepository.cs プロジェクト: Qasim-Rafi/AppSPA
        public async Task <ServiceResponse <object> > ExStudentRegister(ExStudentForRegisterDto model)
        {
            SchoolBranch branch = await _context.SchoolBranch.Where(m => m.BranchName == "ONLINE ACADEMY").FirstOrDefaultAsync();

            var userToCreate = new User
            {
                Username       = model.Username,
                FullName       = model.Username,
                UserTypeId     = (int)Enumm.UserType.OnlineStudent,
                Email          = model.Email,
                ContactNumber  = model.ContactNumber,
                SchoolBranchId = branch.Id,
                //Gender = model.Gender,
                Active          = true,
                CreatedDateTime = DateTime.UtcNow,
                Role            = _context.UserTypes.Where(m => m.Id == (int)Enumm.UserType.OnlineStudent).FirstOrDefault()?.Name
            };

            byte[] passwordHash, passwordSalt;
            Seed.CreatePasswordHash(model.Password, out passwordHash, out passwordSalt);

            userToCreate.PasswordHash = passwordHash;
            userToCreate.PasswordSalt = passwordSalt;

            await _context.Users.AddAsync(userToCreate);

            await _context.SaveChangesAsync();

            var ToAdd = new TutorStudentMapping
            {
                StudentId       = userToCreate.Id,
                TutorId         = model.TutorId,
                SubjectId       = model.SubjectId,
                CreatedDatetime = DateTime.UtcNow,
                Active          = true,
            };
            await _context.TutorStudentMappings.AddAsync(ToAdd);

            await _context.SaveChangesAsync();

            _serviceResponse.Success = true;
            _serviceResponse.Message = "Custom message to online student";
            return(_serviceResponse);
        }
コード例 #10
0
ファイル: LookupRepository.cs プロジェクト: Qasim-Rafi/AppSPA
        public ServiceResponse <object> Quizzes()
        {
            List <Quizzes> list   = new List <Quizzes>();
            SchoolBranch   branch = _context.SchoolBranch.Where(m => m.BranchName == "ONLINE ACADEMY").FirstOrDefault();

            if (branch.Id == _LoggedIn_BranchID || _LoggedIn_BranchID == 0)
            {
                list = _context.Quizzes.Where(m => m.SchoolBranchId == branch.Id).ToList();
            }
            else
            {
                list = _context.Quizzes.Where(m => m.SchoolBranchId == _LoggedIn_BranchID).ToList();
            }
            var ToReturn = _mapper.Map <List <QuizDtoForLookupList> >(list);

            _serviceResponse.Data    = ToReturn;
            _serviceResponse.Success = true;
            return(_serviceResponse);
        }
コード例 #11
0
        public static void SeedSchoolAcademy(DataContext context)
        {
            if (!context.SchoolAcademy.Any())
            {
                //var fileData = System.IO.File.ReadAllText("Data/UserSeedData.json");
                //var schoolAcademies = JsonConvert.DeserializeObject<List<SchoolAcademy>>(fileData);
                var schoolAcademies = context.SchoolAcademy.FirstOrDefault();

                if (schoolAcademies == null)
                {
                    var schoolAcademy = new SchoolAcademy
                    {
                        Name = "School-01",                           //"LGS";
                        PrimaryContactPerson   = "FabIntel",          // "Qasim Rafi";
                        SecondaryContactPerson = "FabIntel2",         // "Ahsan Meraj";
                        PrimaryphoneNumber     = "0000-0000000",      //"03217575840";
                        SecondaryphoneNumber   = "0000-0000000",      // "03003207433";
                        Email            = "*****@*****.**", // "*****@*****.**";
                        PrimaryAddress   = "Garden Town",             // "Allama Iqbal Town";
                        SecondaryAddress = "Lahore",                  // "Garden Tonw";
                        Active           = true
                    };

                    context.SchoolAcademy.Add(schoolAcademy);
                    context.SaveChanges();
                    int schoolAcademyId = schoolAcademy.Id;

                    if (schoolAcademyId > 0)
                    {
                        var schoolBranch = new SchoolBranch {
                            BranchName = "Online Academy", SchoolAcademyID = schoolAcademyId, CreatedDateTime = DateTime.UtcNow, Active = true, RegistrationNumber = "20000001"
                        };

                        context.SchoolBranch.Add(schoolBranch);
                        context.SaveChanges();

                        schoolBranchId = schoolBranch.Id;
                    }
                }
            }
        }
コード例 #12
0
        //private bool verifyPasswordHash(string password, byte[] passwordHash, byte[] passwordSalt)
        //{
        //    using (HMACSHA512 hmac = new HMACSHA512(passwordSalt))
        //    {
        //       var computedHash = hmac.ComputeHash(System.Text.Encoding.UTF8.GetBytes(password));
        //        for (int i=0;i<computedHash.Length; i++)
        //        {
        //            if (computedHash[i] != passwordHash[i])
        //                return false;
        //        }

        //        return true;

        //    }
        //}

        public async Task <ServiceResponse <object> > Register(UserForRegisterDto model, string regNo)
        {
            SchoolBranch branch = null;

            if (model.UserTypeSignUp != null && model.UserTypeSignUp.ToLower() == "school")
            {
                if (!string.IsNullOrEmpty(model.SchoolName))
                {
                    var SchoolExist = _context.SchoolAcademy.Where(m => m.Name.ToLower() == model.SchoolName.ToLower()).FirstOrDefault();
                    if (SchoolExist != null)
                    {
                        _serviceResponse.Success = false;
                        _serviceResponse.Message = CustomMessage.RecordAlreadyExist;
                        return(_serviceResponse);
                    }
                }
                var schools       = _context.SchoolAcademy.OrderByDescending(m => m.Id).ToList();
                var schoolAcademy = new SchoolAcademy
                {
                    Name = string.IsNullOrEmpty(model.SchoolName) ? "School-" + (schools.Count() + 1) : model.SchoolName,
                    PrimaryContactPerson   = model.Username,
                    SecondaryContactPerson = model.Username,
                    PrimaryphoneNumber     = "---",
                    SecondaryphoneNumber   = "---",
                    Email            = model.Email,
                    PrimaryAddress   = "---",
                    SecondaryAddress = "---",
                    Active           = true
                };
                if (model.files != null && model.files.Count() > 0)
                {
                    for (int i = 0; i < model.files.Count(); i++)
                    {
                        var dbPath = _fileRepo.SaveFile(model.files[i]);

                        if (string.IsNullOrEmpty(schoolAcademy.Logo))
                        {
                            schoolAcademy.Logo += dbPath;
                        }
                        else
                        {
                            schoolAcademy.Logo = schoolAcademy.Logo + "||" + dbPath;
                        }
                    }
                }
                _context.SchoolAcademy.Add(schoolAcademy);
                _context.SaveChanges();
                int schoolAcademyId = schoolAcademy.Id;

                if (schoolAcademyId > 0)
                {
                    var branches      = _context.SchoolBranch.OrderByDescending(m => m.Id).ToList();
                    var schoolBranhes = new SchoolBranch
                    {
                        BranchName         = string.IsNullOrEmpty(model.SchoolName) ? "Branch-" + (branches.Count() + 1) : model.SchoolName,
                        SchoolAcademyID    = schoolAcademyId,
                        CreatedDateTime    = DateTime.UtcNow,
                        Active             = true,
                        RegistrationNumber = branches.Count() == 1 ? "10000000" : (Convert.ToInt32(branches.FirstOrDefault().RegistrationNumber) + 1).ToString(),
                        ExamType           = model.ExamType,
                    };

                    _context.AddRange(schoolBranhes);
                    _context.SaveChanges();
                    branch = await _context.SchoolBranch.OrderByDescending(m => m.Id).FirstOrDefaultAsync();
                }
                var userToCreate = new User
                {
                    Username        = model.Username,
                    FullName        = model.FullName,
                    UserTypeId      = (int)Enumm.UserType.Admin,
                    Email           = model.Email,
                    ContactNumber   = model.ContactNumber,
                    SchoolBranchId  = branch.Id,
                    Gender          = "male",
                    Active          = true,
                    CreatedDateTime = DateTime.UtcNow,
                    Role            = _context.UserTypes.Where(m => m.Id == (int)Enumm.UserType.Admin).FirstOrDefault()?.Name
                };
                byte[] passwordHash, passwordSalt;
                Seed.CreatePasswordHash(model.Password, out passwordHash, out passwordSalt);

                userToCreate.PasswordHash = passwordHash;
                userToCreate.PasswordSalt = passwordSalt;

                await _context.Users.AddAsync(userToCreate);

                await _context.SaveChangesAsync();
            }
            else if (model.UserTypeSignUp != null && model.UserTypeSignUp.ToLower() == "tutor")
            {
                branch = await _context.SchoolBranch.Where(m => m.BranchName == "ONLINE ACADEMY").FirstOrDefaultAsync();

                var userToCreate = new User
                {
                    Username        = model.Username,
                    FullName        = model.Username,
                    UserTypeId      = (int)Enumm.UserType.Tutor,
                    Email           = model.Email,
                    ContactNumber   = model.ContactNumber,
                    SchoolBranchId  = branch.Id,
                    Gender          = model.Gender,
                    Active          = true,
                    CreatedDateTime = DateTime.UtcNow,
                    Role            = _context.UserTypes.Where(m => m.Id == (int)Enumm.UserType.Tutor).FirstOrDefault()?.Name
                };
                byte[] passwordHash, passwordSalt;
                Seed.CreatePasswordHash(model.Password, out passwordHash, out passwordSalt);

                userToCreate.PasswordHash = passwordHash;
                userToCreate.PasswordSalt = passwordSalt;

                await _context.Users.AddAsync(userToCreate);

                await _context.SaveChangesAsync();
            }
            else if (model.UserTypeSignUp != null && model.UserTypeSignUp.ToLower() == "student")
            {
                branch = await _context.SchoolBranch.Where(m => m.BranchName == "ONLINE ACADEMY").FirstOrDefaultAsync();

                var userToCreate = new User
                {
                    Username        = model.Username,
                    FullName        = model.Username,
                    UserTypeId      = (int)Enumm.UserType.OnlineStudent,
                    Email           = model.Email,
                    ContactNumber   = model.ContactNumber,
                    SchoolBranchId  = branch.Id,
                    Gender          = model.Gender,
                    Active          = true,
                    CreatedDateTime = DateTime.UtcNow,
                    Role            = _context.UserTypes.Where(m => m.Id == (int)Enumm.UserType.OnlineStudent).FirstOrDefault()?.Name
                };
                byte[] passwordHash, passwordSalt;
                Seed.CreatePasswordHash(model.Password, out passwordHash, out passwordSalt);

                userToCreate.PasswordHash = passwordHash;
                userToCreate.PasswordSalt = passwordSalt;

                await _context.Users.AddAsync(userToCreate);

                await _context.SaveChangesAsync();
            }
            //var UserTypes = _context.UserTypes.ToList();

            _serviceResponse.Success = true;
            _serviceResponse.Message = CustomMessage.Added;
            return(_serviceResponse);
        }