Пример #1
0
        internal StudentAgreementDetailsView GetStudentAgreementDetailsView(string userId, int id)
        {
            var model = new StudentAgreementDetailsView();

            using (var db = new ErasmusDbContext())
            {
                var agreement = db.Agreements.SingleOrDefault(x => x.Id == id);
                if (agreement == null || agreement.ErasmusUserId != userId)
                {
                    return(null);
                }
                model.Student             = agreement.ErasmusUser;
                model.LanguageLevel       = agreement.LanguageLevel;
                model.SourceUniversity    = agreement.SourceUniversity;
                model.Semester            = agreement.Semester;
                model.EndDate             = agreement.EndDate;
                model.TargetUniversity    = agreement.TargetUniversity;
                model.StartDate           = agreement.StartDate;
                model.Language            = agreement.Language;
                model.State               = Enum.GetName(typeof(AgreementState), agreement.State);
                model.StoragePath         = agreement.StoragePath;
                model.FinancingSource     = agreement.FinancingSource;
                model.Scholarship         = agreement.Scholarship;
                model.TargetStudySubjects = agreement.TargetSubjects.ToList();
                model.TargetFaculty       = agreement.TargetFaculty;
                model.SourceFieldOfStudy  = agreement.SourceFieldOfStudy;
                model.TargetFieldOfStudy  = agreement.TargetFieldOfStudy;
                model.SourceStudySubjects = agreement.SourceSubjects.ToList();
                model.SourceFaculty       = agreement.SourceFaculty;
            }
            return(model);
        }
Пример #2
0
 public ActionResult StudentAgreementDetails(int id)
 {
     try
     {
         StudentAgreementDetailsView model = _foreignBusinessLogic.GetStudentAgreementDetailsView(id);
         return(View(model));
     }
     catch (Exception e)
     {
         return(View("Error", new HandleErrorInfo(e, "Foreign", "StudentAgreementDetails")));
     }
 }
Пример #3
0
 public ActionResult StudentAgreementDetails(int id)
 {
     try
     {
         StudentAgreementDetailsView model = _studentBusinessLogic.GetStudentAgreementDetailsView(User.Identity.GetUserId(), id);
         if (model == null)
         {
             return(View("UserError", new UserError("Unable to retrieve the agreement")));
         }
         return(View(model));
     }
     catch (Exception e)
     {
         return(View("Error", new HandleErrorInfo(e, "Student", "StudentAgreementDetails")));
     }
 }
Пример #4
0
        public StudentAgreementDetailsView GetStudentAgreementDetailsView(int id)
        {
            var model = new StudentAgreementDetailsView();

            using (var db = new ErasmusDbContext())
            {
                var agreement = db.Agreements.SingleOrDefault(x => x.Id == id);
                if (agreement == null)
                {
                    return(null);
                }
                model.Student             = agreement.ErasmusUser;
                model.LanguageLevel       = agreement.LanguageLevel;
                model.SourceUniversity    = agreement.SourceUniversity;
                model.Semester            = agreement.Semester;
                model.EndDate             = agreement.EndDate;
                model.TargetUniversity    = agreement.TargetUniversity;
                model.StartDate           = agreement.StartDate;
                model.Language            = agreement.Language;
                model.State               = Enum.GetName(typeof(AgreementState), agreement.State);
                model.StoragePath         = agreement.StoragePath;
                model.FinancingSource     = agreement.FinancingSource;
                model.Scholarship         = agreement.Scholarship;
                model.TargetStudySubjects = agreement.TargetSubjects.ToList();
                model.TargetFaculty       = agreement.TargetFaculty;
                model.SourceFieldOfStudy  = agreement.SourceFieldOfStudy;
                model.TargetFieldOfStudy  = agreement.TargetFieldOfStudy;
                model.SourceStudySubjects = agreement.SourceSubjects.ToList();
                model.SourceFaculty       = agreement.SourceFaculty;
            }
            return(model);

            //NOTE for use with Azure storage account
            //var model = new StudentAgreementDetailsView();
            //using (var db = new ErasmusDbContext())
            //{
            //    var agreement = db.Agreements.SingleOrDefault(x => x.Id == id);
            //    if (agreement == null) throw new ValidationException("Agreement not found.");
            //    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
            //    CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
            //    CloudBlobContainer container = blobClient.GetContainerReference("erasmus");
            //    var blob = container.ServiceClient.GetBlobReferenceFromServer(new Uri(agreement.StoragePath));
            //    using (var memoryStream = new MemoryStream())
            //    {
            //        blob.DownloadToStream(memoryStream);
            //        var text = System.Text.Encoding.UTF8.GetString(memoryStream.ToArray());
            //        var blobData = JsonConvert.DeserializeObject<AgreementStorage>(text);
            //        model = new StudentAgreementDetailsView()
            //        {
            //            Student = blobData.Student,
            //            LanguageLevel = blobData.LanguageLevel,
            //            SourceUniversity = blobData.SourceUniversity,
            //            Semester = blobData.Semester,
            //            EndDate = blobData.EndDate,
            //            TargetUniversity = blobData.TargetUniversity,
            //            StartDate = blobData.StartDate,
            //            Language = blobData.Language,
            //            State = blobData.State,
            //            StoragePath = blobData.StoragePath,
            //            FinancingSource = blobData.FinancingSource,
            //            Scholarship = blobData.Scholarship,
            //            TargetStudySubjects = blobData.TargetStudySubjects,
            //            TargetFaculty = blobData.TargetFaculty,
            //            SourceFieldOfStudy = blobData.SourceFieldOfStudy,
            //            TargetFieldOfStudy = blobData.TargetFieldOfStudy,
            //            SourceStudySubjects = blobData.SourceStudySubjects,
            //            SourceFaculty = blobData.SourceFaculty
            //        };
            //    }
            //}
            //return model;
        }