Esempio n. 1
0
        public StudentModel GetStudent(int id)
        {
            StudentModel          model            = new StudentModel();
            LocalAddressModel     localAddress     = new LocalAddressModel();
            PermanentAddressModel permanentAddress = new PermanentAddressModel();
            Student student = dbContext.Students.FirstOrDefault(x => x.ID == id);

            if (student != null)
            {
                model.FirstName           = student.FirstName;
                model.LastName            = student.LastName;
                model.DateOfBirth         = student.DateOfBirth;
                model.FatherName          = student.FatherName;
                model.MotherName          = student.MotherName;
                model.FatherQualification = student.FatherQualification;
                model.MotherQualification = student.MotherQualification;
                model.FatherOccupation    = student.FatherOccupation;
                model.Gender        = student.Gender;
                model.Phone         = student.Phone;
                model.Email         = student.Email;
                model.DateOfJoining = student.DateOfJoining;
                model.DateOfLeaving = student.DateOfLeaving;
                model.Category      = student.Category;
                model.Cast          = student.Cast;
                model.Religion      = student.Religion;

                var permanentAdd = dbContext.Address.FirstOrDefault(x => x.StudentID == id && x.AddressType == AddressType.Permanent);
                if (permanentAdd != null)
                {
                    permanentAddress.HouseNumber = permanentAdd.HouseNumber;
                    permanentAddress.Street      = permanentAdd.Street;
                    permanentAddress.City        = permanentAdd.City;
                    permanentAddress.State       = permanentAdd.State;
                    permanentAddress.ZipCode     = permanentAdd.ZipCode;
                    permanentAddress.LandMark    = permanentAdd.LandMark;
                }
                var localAdd = dbContext.Address.FirstOrDefault(x => x.StudentID == id && x.AddressType == AddressType.Temperary);
                if (localAdd != null)
                {
                    localAddress.HouseNumber = localAdd.HouseNumber;
                    localAddress.Street      = localAdd.Street;
                    localAddress.City        = localAdd.City;
                    localAddress.State       = localAdd.State;
                    localAddress.ZipCode     = localAdd.ZipCode;
                    localAddress.LandMark    = localAdd.LandMark;
                }
            }
            else
            {
                throw new ApiException("This user does not exists.");
            }
            model.LocalAddress     = localAddress;
            model.PermanentAddress = permanentAddress;
            return(model);
        }
Esempio n. 2
0
        public void UpdateStudent(int id, StudentModel model)
        {
            try
            {
                if (model == null)
                {
                    throw new Exception("Invalid Value");
                }
                if (string.IsNullOrEmpty(model.FirstName))
                {
                    throw new Exception("please Enter First Name");
                }
                if (string.IsNullOrEmpty(model.LastName))
                {
                    throw new Exception("Please enter Last Name");
                }
                if (model.DateOfBirth == null)
                {
                    throw new Exception("Please enter Date of birth");
                }
                if (string.IsNullOrEmpty(model.FatherName))
                {
                    throw new Exception("Please enter Father Name");
                }
                if (string.IsNullOrEmpty(model.MotherName))
                {
                    throw new Exception("Please enter Mother Name");
                }
                if (string.IsNullOrEmpty(model.FatherQualification))
                {
                    throw new Exception("Please enter Father Qualification");
                }
                if (string.IsNullOrEmpty(model.MotherQualification))
                {
                    throw new Exception("Please enter Mother Qualification");
                }
                if (string.IsNullOrEmpty(model.FatherOccupation))
                {
                    throw new Exception("Please enter Father Occupation");
                }
                if (string.IsNullOrEmpty(model.Phone))
                {
                    throw new Exception("Please enter Contact No.");
                }
                //if (string.IsNullOrEmpty(studentModel.Gender))
                //{
                //    throw new Exception("Please select Gender");
                //}
                if (string.IsNullOrEmpty(model.Email))
                {
                    throw new Exception("Please enter Email ID");
                }
                if (model.LocalAddress == null)
                {
                    throw new Exception("Please enter Local Address");
                }
                if (model.PermanentAddress == null)
                {
                    throw new Exception("Please enter Permanent Address");
                }
                if (model.DateOfJoining == null)
                {
                    throw new Exception("Please enter Date of Joining");
                }
                if (string.IsNullOrEmpty(model.Category))
                {
                    throw new Exception("Please select Category");
                }
                if (string.IsNullOrEmpty(model.Cast))
                {
                    throw new Exception("Please select Cast");
                }
                if (string.IsNullOrEmpty(model.Religion))
                {
                    throw new Exception("Please select Religion");
                }
                Student student = dbContext.Students.FirstOrDefault(x => x.ID == id);
                if (student != null)
                {
                    student.FirstName           = model.FirstName;
                    student.LastName            = model.LastName;
                    student.DateOfBirth         = model.DateOfBirth;
                    student.FatherName          = model.FatherName;
                    student.MotherName          = model.MotherName;
                    student.FatherQualification = model.FatherQualification;
                    student.MotherQualification = model.MotherQualification;
                    student.FatherOccupation    = model.FatherOccupation;
                    student.Gender        = model.Gender;
                    student.DateOfJoining = model.DateOfJoining;
                    student.DateOfLeaving = model.DateOfLeaving;
                    student.Email         = model.Email;
                    student.Category      = model.Category;
                    student.Cast          = model.Cast;
                    student.Religion      = model.Religion;
                    dbContext.SaveChanges();
                }
                LocalAddressModel localAddress = model.LocalAddress;
                //PermanentAddressModel permanentAddress = new PermanentAddressModel();
                var address = dbContext.Address.FirstOrDefault(x => x.StudentID == id);
                address.City        = localAddress.City;
                address.State       = localAddress.State;
                address.ZipCode     = localAddress.ZipCode;
                address.AddressType = AddressType.Temperary;
                address.Street      = localAddress.Street;
                address.LandMark    = localAddress.LandMark;
                address.HouseNumber = localAddress.HouseNumber;
                PermanentAddressModel permanentAddress = model.PermanentAddress;
                address.City        = permanentAddress.City;
                address.State       = permanentAddress.State;
                address.ZipCode     = permanentAddress.ZipCode;
                address.AddressType = AddressType.Permanent;
                address.Street      = permanentAddress.Street;
                address.LandMark    = permanentAddress.LandMark;
                address.HouseNumber = permanentAddress.HouseNumber;
                dbContext.SaveChanges();
            }

            catch (Exception exception)
            {
                throw new ApiException(exception.Message);
            }
        }