Esempio n. 1
0
        public InstitutionModel GetDefaultInstitutions()
        {
            InstitutionModel model = new InstitutionModel();

            //Demo purposes only.  The OAuth tokens returned by the SAML assertion are valid for 1 hour and do not need to be requested before each API call.
            SamlRequestValidator validator = new SamlRequestValidator(AggCatAppSettings.Certificate,
                                                                      AggCatAppSettings.ConsumerKey,
                                                                      AggCatAppSettings.ConsumerSecret,
                                                                      AggCatAppSettings.SamlIdentityProviderId,
                                                                      AggCatAppSettings.CustomerId);
            ServiceContext ctx = new ServiceContext(validator);
            AggregationCategorizationService svc = new AggregationCategorizationService(ctx);

            try
            {
                List <Institution> institutions = svc.GetInstitutions().institution.ToList <Institution>();
                model.Institutions = institutions;
                model.Error        = null;
                model.Success      = true;
            }
            catch (AggregationCategorizationException ex)
            {
                model.Institutions = null;
                model.Error        = ex.ToString();
                model.Success      = false;
            }

            return(model);
        }
Esempio n. 2
0
        public ActionResult Create(LevelModel model, int Institution)
        {
            try
            {
                using (ISession session = NHibernateHelper.OpenSession())
                {
                    InstitutionModel institutionModel = session.Get <InstitutionModel>(Institution);

                    model.Institution = institutionModel;

                    using (ITransaction transaction = session.BeginTransaction())
                    {
                        session.Save(model);
                        transaction.Commit();
                    }
                }

                return(RedirectToAction("Index").WithMessage(Languages.Success, "alert-success", "glyphicon glyphicon-ok-sign"));
            }
            catch
            {
                return(RedirectToAction("Index").WithMessage(Languages.Error, "alert-danger", "glyphicon glyphicon-remove-sign"));

                throw;
            }
        }
Esempio n. 3
0
        internal InstitutionModel GetInstitutionDetails(InstitutionModel institutionModel)
        {
            try
            {
                //Demo purposes only.  The OAuth tokens returned by the SAML assertion are valid for 1 hour and do not need to be requested before each API call.
                SamlRequestValidator validator = new SamlRequestValidator(AggCatAppSettings.Certificate,
                                                                          AggCatAppSettings.ConsumerKey,
                                                                          AggCatAppSettings.ConsumerSecret,
                                                                          AggCatAppSettings.SamlIdentityProviderId,
                                                                          AggCatAppSettings.CustomerId);
                ServiceContext ctx = new ServiceContext(validator);
                AggregationCategorizationService svc = new AggregationCategorizationService(ctx);
                institutionModel.InstitutionDetail = svc.GetInstitutionDetails(institutionModel.InstitutionId);
                institutionModel.Success           = true;
                institutionModel.Error             = null;
            }
            catch (AggregationCategorizationException ex)
            {
                institutionModel.InstitutionDetail = null;
                institutionModel.Success           = false;
                institutionModel.Error             = ex.ToString();
            }

            return(institutionModel);
        }
Esempio n. 4
0
        public ActionResult Delete(int modelId)
        {
            try
            {
                using (ISession session = NHibernateHelper.OpenSession())
                {
                    InstitutionModel institution = session.Get <InstitutionModel>(modelId);

                    using (ITransaction transaction = session.BeginTransaction())
                    {
                        session.Delete(institution);
                        transaction.Commit();
                    }

                    return(RedirectToAction("Index").WithMessage(Languages.Success, "alert-success", "glyphicon glyphicon-ok-sign"));
                }
            }
            catch (ADOException)
            {
                return(RedirectToAction("Index").WithMessage(Languages.ADOException, "alert-warning", "glyphicon glyphicon-exclamation-sign"));

                throw;
            }
            catch (System.Exception)
            {
                return(RedirectToAction("Index").WithMessage(Languages.Error, "alert-danger", "glyphicon glyphicon-remove-sign"));

                throw;
            }
        }
Esempio n. 5
0
        private InstitutionModel getInstitution(int id, DepartmentModel department, AddressModel state)
        {
            DBConnection     testconn    = new DBConnection();
            InstitutionModel inst        = new InstitutionModel();
            string           institution = "SELECT institution, institution_website, associates, bachelors, masters, doctoral FROM Institutions WHERE id = @institutionId";

            Dictionary <string, Object> query_params = new Dictionary <string, Object>();

            query_params.Add("@institutionId", id);

            SqlDataReader dataReader = testconn.ReadFromProduction(institution, query_params);

            if (dataReader.HasRows)
            {
                while (dataReader.Read())
                {
                    string name       = dataReader.GetValue(0).ToString();
                    string website    = dataReader.GetValue(1).ToString();
                    bool   associates = (bool)dataReader.GetValue(2);
                    bool   bachelors  = (bool)dataReader.GetValue(3);
                    bool   masters    = (bool)dataReader.GetValue(4);
                    bool   phd        = (bool)dataReader.GetValue(5);

                    inst = new InstitutionModel(id, name, website, department, state, bachelors, associates, masters, phd);
                }
            }

            testconn.CloseDataReader();
            testconn.CloseConnection();

            return(inst);
        }
Esempio n. 6
0
        public ActionResult Create(InstitutionModel institution)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (ISession session = NHibernateHelper.OpenSession())
                    {
                        using (ITransaction transaction = session.BeginTransaction())
                        {
                            session.Save(institution);
                            transaction.Commit();
                        }

                        return(RedirectToAction("Index").WithMessage(Languages.Success, "alert-success", "glyphicon glyphicon-ok-sign"));
                    }
                }
                else
                {
                    return(RedirectToAction("Index").WithMessage(Languages.InvalidModelState, "alert-warning", "glyphicon glyphicon-exclamation-sign"));
                }
            }
            catch (System.Exception)
            {
                return(RedirectToAction("Index").WithMessage(Languages.Error, "alert-danger", "glyphicon glyphicon-remove-sign"));

                throw;
            }
        }
Esempio n. 7
0
        public async Task ChangeInstituteStatus(InstitutionModel model)
        {
            var Institute = await _dbContext.Institutions.Where(item => item.Id == model.InstitutionId).FirstOrDefaultAsync();

            Institute.Status = model.Status;
            await _dbContext.SaveChangesAsync();
        }
Esempio n. 8
0
        private List <InstitutionModel> getInstitutions(string query)
        {
            DBConnection            testconn     = new DBConnection();
            List <InstitutionModel> institutions = new List <InstitutionModel>();

            //query = "SELECT TOP 100 institution_id, department_id, state_id FROM institution_has_state_has_department";
            SqlDataReader dataReader = testconn.ReadFromTest(query);

            if (dataReader.HasRows)
            {
                while (dataReader.Read())
                {
                    int inst_id  = Int32.Parse(dataReader.GetValue(0).ToString());
                    int dept_id  = Int32.Parse(dataReader.GetValue(1).ToString());
                    int state_id = Int32.Parse(dataReader.GetValue(2).ToString());

                    DepartmentModel  department  = getDepartment(dept_id);
                    AddressModel     state       = getState(state_id);
                    InstitutionModel institution = getInstitution(inst_id, department, state);



                    institutions.Add(institution);
                }
            }

            testconn.CloseDataReader();
            testconn.CloseConnection();
            return(institutions);
        }
Esempio n. 9
0
 public Institution Map(InstitutionModel model)
 {
     return(new Institution
     {
         Id = model.Id,
         Name = model.Name
     });
 }
Esempio n. 10
0
        public ActionResult Edit(int id)
        {
            using (ISession session = NHibernateHelper.OpenSession())
            {
                InstitutionModel institution = session.Get <InstitutionModel>(id);

                return(View(institution));
            }
        }
Esempio n. 11
0
        public ActionResult DiscoverAndAddLogin(string id)
        {
            long             longId = Convert.ToInt64(id);
            InstitutionModel model  = this.serviceOperations.GetInstitutionDetails(new InstitutionModel {
                InstitutionId = longId
            });

            Session["InstitutionDetail"] = model.InstitutionDetail;
            return(View(model));
        }
        public async Task <int> CreateInstitute(InstitutionModel model)
        {
            int result = 0;

            try
            {
                await _connection.OpenAsync();

                var cmd = new MySqlCommand("Create_Institute", _connection);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("InstituteName", model.Name);
                cmd.Parameters.AddWithValue("InstituteBranch", model.BranchName);
                cmd.Parameters.AddWithValue("InstituteDescription", model.Description);
                cmd.Parameters.AddWithValue("BoardId", model.BoardId);
                cmd.Parameters.AddWithValue("TypeId", model.TypeId);
                cmd.Parameters.AddWithValue("CreatedBy", model.Actor);

                cmd.Parameters.AddWithValue("MailingAddLine1", model.MailingAddress.AddressLine1);
                cmd.Parameters.AddWithValue("MailingAddLine2", model.MailingAddress.AddressLine2);
                cmd.Parameters.AddWithValue("MailingAddLine3", model.MailingAddress.AddressLine3);
                cmd.Parameters.AddWithValue("MailingCity", model.MailingAddress.City);
                cmd.Parameters.AddWithValue("MailingState", model.MailingAddress.State);
                cmd.Parameters.AddWithValue("MailingCountry", model.MailingAddress.Country);
                cmd.Parameters.AddWithValue("MailingZip", model.MailingAddress.Zipcode);

                cmd.Parameters.AddWithValue("BillingAddLine1", model.BillingAddress.AddressLine1);
                cmd.Parameters.AddWithValue("BillingAddLine2", model.BillingAddress.AddressLine2);
                cmd.Parameters.AddWithValue("BillingAddLine3", model.BillingAddress.AddressLine3);
                cmd.Parameters.AddWithValue("BillingCity", model.BillingAddress.City);
                cmd.Parameters.AddWithValue("BillingState", model.BillingAddress.State);
                cmd.Parameters.AddWithValue("BillingCountry", model.BillingAddress.Country);
                cmd.Parameters.AddWithValue("BillingZip", model.BillingAddress.Zipcode);

                cmd.Parameters.AddWithValue("LandNumber", model.ContactDetail.LandLineNumber);
                cmd.Parameters.AddWithValue("AltLandline", model.ContactDetail.AltLandLineNumber);
                cmd.Parameters.AddWithValue("MobNumber", model.ContactDetail.MobileNumber);
                cmd.Parameters.AddWithValue("AltMobNumber", model.ContactDetail.AltMobileNumber);
                cmd.Parameters.AddWithValue("Email", model.ContactDetail.EmailId);
                cmd.Parameters.AddWithValue("AltEmail", model.ContactDetail.AltEmailId);
                var dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    result = Convert.ToInt32(dr["InstituteId"]);
                }
                return(result);
            }
            catch
            {
                throw;
            }
            finally
            {
                await _connection.CloseAsync();
            }
        }
Esempio n. 13
0
        public ActionResult Index(InstitutionModel institutionModel)
        {
            InstitutionModel model = this.serviceOperations.GetInstitutionDetails(institutionModel);

            if (model.Institutions == null)
            {
                model.Institutions = Session["Institutions"] as List <Institution>;
            }

            return(View(model));
        }
Esempio n. 14
0
 public bool UpdateInstitution(InstitutionModel model)
 {
     if (model.Id == null)
     {
         return(false);
     }
     if (_institutionRepository.Has(model.Id.Value))
     {
         var entity = model.ToEntity();
         return(_institutionRepository.Update(entity));
     }
     return(false);
 }
Esempio n. 15
0
        public TranscriptsControllerUnitTests()
        {
            _mockInstitutionRepository     = new Mock <IInstitutionRepository>();
            _mockTranscriptProviderService = new Mock <ITranscriptProviderService>();
            _mockTranscriptRepository      = new Mock <ITranscriptRepository>();
            _mockTranscriptService         = new Mock <ITranscriptService>();
            _mockLinqWrapperService        = new Mock <ILinqWrapperService>();
            var _mockCurrentSchool = new InstitutionModel
            {
                Id = 1234,
                InstitutionName = "Test Institution",
                InstitutionType = InstitutionTypeEnum.School
            };

            _mockInstitutionRepository.Setup(ir => ir.GetDefaultInstitutionByEducatorIdAsync(It.IsAny <int>())).ReturnsAsync(_mockCurrentSchool);
        }
Esempio n. 16
0
        public ActionResult DiscoverAndAddLogin(InstitutionModel model)
        {
            model.InstitutionDetail = Session["InstitutionDetail"] as InstitutionDetail;
            DiscoverAddModel discoverModel = this.serviceOperations.DiscoverAndAdd(model);

            Session["DAM"] = discoverModel;
            if (discoverModel.MFA)
            {
                Session.Remove("InstitutionDetail");
                return(RedirectToAction("DiscoverAndAddChallenge", "Institutions"));
            }
            else
            {
                Session.Remove("InstitutionDetail");
                return(RedirectToAction("DiscoverAndAddResult", "Institutions"));
            }
        }
Esempio n. 17
0
        public void SaveAcademic()
        {
            //arrange
            IFlowManager flowManager = serviceProvider.GetRequiredService <IFlowManager>();
            var          academic    = flowManager.EnrollmentRepository.GetAsync <AcademicModel, Academic>
                                       (
                s => s.UserId == 1,
                null,
                new LogicBuilder.Expressions.Utils.Expansions.SelectExpandDefinition
            {
                ExpandedItems = new System.Collections.Generic.List <LogicBuilder.Expressions.Utils.Expansions.SelectExpandItem>
                {
                    new LogicBuilder.Expressions.Utils.Expansions.SelectExpandItem
                    {
                        MemberName = "Institutions"
                    }
                }
            }
                                       ).Result.Single();

            academic.LastHighSchoolLocation = "FL";
            InstitutionModel institution = academic.Institutions.First();

            institution.EndYear               = "2222";
            academic.EntityState              = LogicBuilder.Domain.EntityStateType.Modified;
            institution.EntityState           = LogicBuilder.Domain.EntityStateType.Modified;
            flowManager.FlowDataCache.Request = new SaveEntityRequest {
                Entity = academic
            };

            //act
            System.Diagnostics.Stopwatch stopWatch = System.Diagnostics.Stopwatch.StartNew();
            flowManager.Start("saveacademic");
            stopWatch.Stop();
            this.output.WriteLine("Saving valid academic = {0}", stopWatch.Elapsed.TotalMilliseconds);

            //assert
            Assert.True(flowManager.FlowDataCache.Response.Success);
            Assert.Empty(flowManager.FlowDataCache.Response.ErrorMessages);

            AcademicModel model = (AcademicModel)((SaveEntityResponse)flowManager.FlowDataCache.Response).Entity;

            Assert.Equal("FL", model.LastHighSchoolLocation);
            Assert.Equal("2222", model.Institutions.First().EndYear);
        }
Esempio n. 18
0
 public IActionResult UpdateInstitution([FromForm] InstitutionModel model)
 {
     try
     {
         var result = _institutionService.UpdateInstitution(model);
         if (result == null)
         {
             return(BadRequest("Ошибка при сохранении данных"));
         }
         _logger.LogInformation($"Данные о учебном заведении: {model.Name}, успешно обновлены");
         return(Ok(result));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, "Ошибка входе обновления данных о учебном заведении");
         return(BadRequest(ex));
     }
 }
Esempio n. 19
0
        public ActionResult Index()
        {
            InstitutionModel model = null;

            if (Session["Institutions"] == null)
            {
                model = this.serviceOperations.GetDefaultInstitutions();
                Session["Institutions"] = model.Institutions;
            }
            else
            {
                model = new InstitutionModel {
                    Institutions = Session["Institutions"] as List <Institution>, Error = null, Success = true
                };
            }

            return(View(model));
        }
Esempio n. 20
0
 public static Institution ToEntity(this InstitutionModel model)
 {
     if (model == null)
     {
         throw new NullReferenceException("InstitutionModel is null");
     }
     return(new Institution()
     {
         Id = model.Id.HasValue? model.Id.Value: 0,
         Name = model.Name,
         City = model.City,
         Department = model.Department,
         Specialty = model.Specialty,
         Degree = model.Degree,
         From = model.From,
         To = model.To,
         ResumeId = model.ResumeId.HasValue ? model.ResumeId.Value : 0
     });
 }
Esempio n. 21
0
        public async Task <InstitutionModel> GetInstituteDetails(int InstituteId)
        {
            var Institute = await _dbContext.Institutions.Where(item => item.Id == InstituteId).FirstOrDefaultAsync();

            var Institution = new InstitutionModel {
                InstitutionName = Institute.InstituteName
            };
            var Providers = await _dbContext.Providers.Where(item => item.InstituteId == Institute.Id).ToListAsync();

            List <KeyValuePair <string, string> > mappings = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("Id", "ProviderId")
            };

            foreach (Provider p in Providers)
            {
                Institution.Providers.Add(p.MapTo <ProviderModel>(mappings: mappings));
            }
            return(Institution);
        }
        public async Task <IActionResult> Post(InstitutionModel model)
        {
            var username = ApplicationUtility.GetTokenAttribute(Request.Headers["Authorization"], "sub");
            var service  = new InstituteRepositoryService(connString);
            InstituteAmazonAccount amazonAccountModel = null;

            model.Actor = username;
            var id = await service.CreateInstitute(model);

            if (model.CloudAccountRequired)
            {
                var bucketSevice = new AmazonS3Service();
                var bucketName   = GetName(model.Name);
                await bucketSevice.CreateBucketToS3(bucketName);

                var iamService   = new AmazonIAMService();
                var iamUserName  = GetName(model.Name);
                var accesKeyInfo = await iamService.CreateIAMUser("/", iamUserName);

                amazonAccountModel = new InstituteAmazonAccount()
                {
                    AccessKey   = accesKeyInfo.AccessKey,
                    Actor       = username,
                    BucketName  = bucketName,
                    IamUsername = iamUserName,
                    InstituteId = id,
                    SecretKey   = accesKeyInfo.SecurityKey
                };
                await service.CreateInstituteAmazonAccount(amazonAccountModel);
            }

            var response = new GenericResponse <string>()
            {
                IsSuccess    = true,
                Message      = "Institute created successfully.",
                ResponseCode = 200,
                Result       = "Success"
            };

            return(Ok(response));
        }
Esempio n. 23
0
        public async Task BulkSendTranscriptRequest_should_return_bad_request_for_invalid_input()
        {
            // Arrange:
            var currentSchool = new InstitutionModel
            {
                Id = 1234,
                InstitutionName = "Institution Name",
                InstitutionType = InstitutionTypeEnum.School
            };

            _mockInstitutionRepository.Setup(ir => ir.GetDefaultInstitutionByEducatorIdAsync(It.IsAny <int>())).ReturnsAsync(currentSchool);
            _mockTranscriptRequestRepository.Setup(trr => trr.GetSendTranscriptByTranscriptRequestIdListAsync(It.IsAny <List <int> >())).ReturnsAsync((List <SendTranscriptViewModel>)null);

            // Act
            var actionResult = await CreateController().BulkSendTranscriptRequest(new List <int> {
                1, 2
            });

            //Assert
            var contentResult = new BadRequestObjectResult(actionResult);

            Assert.AreEqual(StatusCodes.Status400BadRequest, contentResult.StatusCode);
        }
Esempio n. 24
0
        public async Task BulkSendTranscriptRequest_should_return_ok()
        {
            // Arrange:
            var currentSchool = new InstitutionModel
            {
                Id = 1234,
                InstitutionName = "Institution Name",
                InstitutionType = InstitutionTypeEnum.School
            };

            _mockInstitutionRepository.Setup(ir => ir.GetDefaultInstitutionByEducatorIdAsync(It.IsAny <int>())).ReturnsAsync(currentSchool);
            var sendTranscriptList = new List <SendTranscriptViewModel>
            {
                new SendTranscriptViewModel {
                    TranscriptRequestId = 1
                },
                new SendTranscriptViewModel {
                    TranscriptRequestId = 2
                }
            };

            _mockTranscriptRequestRepository.Setup(trr => trr.GetSendTranscriptByTranscriptRequestIdListAsync(It.IsAny <List <int> >())).ReturnsAsync(sendTranscriptList);

            // Act
            var actionResult = await CreateController().BulkSendTranscriptRequest(new List <int> {
                1, 2
            });

            //Assert
            // Make sure the correct service methods are called
            _mockTranscriptProviderService.Verify(tps => tps.BulkSendTranscriptRequestAsync(sendTranscriptList, currentSchool.Id, 456), Times.Once);

            var contentResult = new OkObjectResult(actionResult);

            Assert.AreEqual(StatusCodes.Status200OK, contentResult.StatusCode);
        }
Esempio n. 25
0
        public ActionResult Edit(LevelModel model, int Institution)
        {
            try
            {
                using (ISession session = NHibernateHelper.OpenSession())
                {
                    LevelModel persistentModel = session.Get <LevelModel>(model.Id);

                    InstitutionModel institutionModel = session.Get <InstitutionModel>(Institution);

                    persistentModel.Institution = institutionModel;
                    persistentModel.Name        = model.Name;
                    persistentModel.LevelType   = model.LevelType;

                    using (ITransaction transaction = session.BeginTransaction())
                    {
                        session.Save(persistentModel);
                        transaction.Commit();
                    }
                }

                return(RedirectToAction("Index").WithMessage(Languages.Success, "alert-success", "glyphicon glyphicon-ok-sign"));
            }
            catch (PropertyValueException)
            {
                return(RedirectToAction("Index").WithMessage(Languages.Error, "alert-warning", "glyphicon glyphicon-exclamation-sign"));

                throw;
            }
            catch (System.Exception)
            {
                return(RedirectToAction("Index").WithMessage(Languages.Error, "alert-danger", "glyphicon glyphicon-remove-sign"));

                throw;
            }
        }
Esempio n. 26
0
        internal DiscoverAddModel DiscoverAndAdd(InstitutionModel institutionModel)
        {
            DiscoverAddModel discoverAddModel = new DiscoverAddModel();

            try
            {
                //Demo purposes only.  The OAuth tokens returned by the SAML assertion are valid for 1 hour and do not need to be requested before each API call.
                SamlRequestValidator validator = new SamlRequestValidator(AggCatAppSettings.Certificate,
                                                                          AggCatAppSettings.ConsumerKey,
                                                                          AggCatAppSettings.ConsumerSecret,
                                                                          AggCatAppSettings.SamlIdentityProviderId,
                                                                          AggCatAppSettings.CustomerId);
                ServiceContext ctx = new ServiceContext(validator);
                AggregationCategorizationService svc = new AggregationCategorizationService(ctx);

                InstitutionLogin  instLogin   = new InstitutionLogin();
                Credentials       creds       = new Credentials();
                List <Credential> credentials = new List <Credential>();
                Credential        cred        = new Credential();
                cred.name  = institutionModel.InstitutionDetail.keys.FirstOrDefault(k => k.displayOrder == 1).name;
                cred.value = institutionModel.Value1;
                credentials.Add(cred);

                cred       = new Credential();
                cred.name  = institutionModel.InstitutionDetail.keys.FirstOrDefault(k => k.displayOrder == 2).name;
                cred.value = institutionModel.Value2;
                credentials.Add(cred);

                IEnumerable <InstitutionDetailKey> idk = institutionModel.InstitutionDetail.keys.Where(k => k.displayOrder != 1 && k.displayOrder != 2);
                foreach (InstitutionDetailKey item in idk)
                {
                    cred       = new Credential();
                    cred.name  = item.name;
                    cred.value = item.val;
                    credentials.Add(cred);
                }

                creds.credential          = credentials.ToArray();
                instLogin.AnyIntuitObject = creds;

                Challenges       challenges       = null;
                ChallengeSession challengeSession = null;
                AccountList      accountList      = svc.DiscoverAndAddAccounts(institutionModel.InstitutionDetail.institutionId, instLogin, out challenges, out challengeSession);
                discoverAddModel.AccountList      = accountList;
                discoverAddModel.Challenges       = challenges;
                discoverAddModel.ChallengeSession = challengeSession;
                discoverAddModel.Success          = true;
                discoverAddModel.Error            = null;
                if (accountList == null && challenges != null)
                {
                    discoverAddModel.MFA = true;
                }
            }
            catch (AggregationCategorizationException ex)
            {
                discoverAddModel.AccountList      = null;
                discoverAddModel.Challenges       = null;
                discoverAddModel.ChallengeSession = null;
                discoverAddModel.Success          = false;
                discoverAddModel.Error            = ex.ToString();
            }

            return(discoverAddModel);
        }
Esempio n. 27
0
 public async Task <bool> Update(InstitutionModel institution)
 {
     _context.Instituties.Update(institution);
     return(await _context.SaveChangesAsync() > 0);
 }
Esempio n. 28
0
        public object Post(InstitutionModel model)
        {
            var currentUser = User.Identity.GetEmoloyee();
            //当前存在的数据(删除)
            var existing = _correctingInsService.GetCorrectingInss().FirstOrDefault(n => n.OriginalId == model.Id);

            if (existing != null && existing.EmpCode != currentUser.Code)
            {
                var employee = _employeeService.GetEmployees().Where(n => n.Code == existing.EmpCode).FirstOrDefault();
                var res      = new ResponseModel {
                    Error = true, Message = ""
                };
                if (employee != null)
                {
                    res.Message = employee.Name + "抢先一步正在更新";
                    return(res);
                }
            }
            if (existing != null && existing.EmpCode == currentUser.Code)
            {
                var tasks = _correctingInsService.GetCorrectingInss().Where(n => n.TaskId == existing.TaskId);
                foreach (var task in tasks)
                {
                    task.IsDeleted = true;
                    task.DateTime  = DateTime.Now;
                }
            }
            var taskId   = Guid.NewGuid();
            var taskCode = _correctingInsService.GetMaxTaskCode() + 1;

            //先添加childs
            if (model.Childrens != null)
            {
                foreach (var child in model.Childrens)
                {
                    _correctingInsService.Insert(new CorrectingIns
                    {
                        Id                       = Guid.NewGuid(),
                        TaskCode                 = taskCode,
                        TaskId                   = taskId,
                        OriginalId               = child.Id == Guid.Empty ? (Guid?)null : child.Id,
                        Name                     = child.Name != null ? child.Name : null,
                        Address                  = child.Address != null ? child.Address : null,
                        InsLevel                 = child.LevelName != null?child.LevelName:null,
                        InsTier                  = child.TierName != null? child.TierName:null,
                        InsType                  = child.InstitutionType != null ? child.InstitutionType : null,
                        InsAttribute             = child.Attribute != null ? child.Attribute : null,
                        InsNature                = child.Nature != null ? child.Nature : null,
                        InsSpecializedDepartment = child.SpecializedDepartment != null ? child.SpecializedDepartment : null,
                        TelNum                   = child.TelNum != null ? child.TelNum : null,
                        Outpatients              = child.Outpatients != null ? child.Outpatients : null,
                        Beds                     = child.Beds != null ? child.Beds : null,
                        ParentId                 = model.Id,
                        DateTime                 = DateTime.Now,
                        EmpCode                  = currentUser.Code,
                        EmpName                  = currentUser.Name,
                        LocationCode             = child.LocationCode,
                        LocationName             = child.LocationName,
                        IsPrimary                = false
                    });
                }
            }
            //再添加Institution
            _correctingInsService.Insert(new CorrectingIns
            {
                Id                       = Guid.NewGuid(),
                IsPrimary                = true,
                TaskId                   = taskId,
                TaskCode                 = taskCode,
                OriginalId               = model.Id,
                Name                     = model.Name,
                Address                  = model.Address != null ? model.Address : null,
                InsLevel                 = model.LevelName != null ? model.LevelName : null,
                InsTier                  = model.TierName != null ? model.TierName : null,
                InsType                  = model.InstitutionType != null ? model.InstitutionType : null,
                InsAttribute             = model.Attribute != null ? model.Attribute : null,
                InsNature                = model.Nature != null ? model.Nature : null,
                InsSpecializedDepartment = model.SpecializedDepartment != null ? model.SpecializedDepartment : null,
                TelNum                   = model.TelNum != null ? model.TelNum : null,
                Outpatients              = model.Outpatients != null ? model.Outpatients : null,
                Beds                     = model.Beds != null ? model.Beds : null,
                ParentId                 = model.Parent != null ? model.Parent.Id : (Guid?)null,
                DateTime                 = DateTime.Now,
                EmpCode                  = currentUser.Code,
                EmpName                  = currentUser.Name,
                LocationCode             = model.LocationCode,
                LocationName             = model.LocationName,
            });

            try
            {
                _correctingInsService.Update();
            }
            catch (Exception ex)
            {
                return(new ResponseModel {
                    Error = true
                });
            }


            return(new ResponseModel {
                Error = false
            });
        }
Esempio n. 29
0
        public async Task GetTranscriptRequestProgressForCurrentSchool_should_return_ok_with_result()
        {
            // Arrange:
            var currentSchool = new InstitutionModel
            {
                Id = 1234,
                InstitutionName = "Institution Name",
                InstitutionType = InstitutionTypeEnum.School
            };

            _mockInstitutionRepository.Setup(ir => ir.GetDefaultInstitutionByEducatorIdAsync(It.IsAny <int>())).ReturnsAsync(currentSchool);
            var requestsProgressBySchool = new List <TranscriptRequestProgressViewModel> {
                new TranscriptRequestProgressViewModel
                {
                    Id     = 1234,
                    InunId = "1234",
                    ReceivingInstitutionCode = 1234,
                    UserAccountId            = 1234,
                    AvatarFileName           = "avatar.jpg",
                    SchoolCountryType        = CountryType.US,
                    StudentName                   = "FirstName, LastName",
                    DateOfBirth                   = new DateTime(2000, 5, 23),
                    GradeId                       = 11,
                    GradeKey                      = "GRADE_11",
                    StudentId                     = "1234",
                    TranscriptRequestId           = 12,
                    ReceivingInstitutionName      = "Institution Name",
                    ReceivingInstitutionCity      = "City",
                    ReceivingInstitutionStateCode = "SC",
                    RequestedDate                 = new DateTime(),
                    TranscriptStatus              = TranscriptRequestStatus.Submitted,
                    TranscriptStatusKey           = "SUBMITTED",
                    TranscriptStatusDate          = new DateTime()
                }
            };

            _mockTranscriptRequestRepository.Setup(rr => rr.GetTranscriptRequestProgressBySchoolIdAsync(It.IsAny <int>())).ReturnsAsync(requestsProgressBySchool);
            var requestsProgressBySchoolLinqed = new ItemsCountModel <TranscriptRequestProgressViewModel>
            {
                Items = requestsProgressBySchool,
                Count = 1
            };

            _mockLinqWrapperService.Setup(ls => ls.GetLinqedList(
                                              It.IsAny <IEnumerable <TranscriptRequestProgressViewModel> >(),
                                              It.IsAny <Func <TranscriptRequestProgressViewModel, bool> >(),
                                              It.IsAny <string>(),
                                              It.IsAny <string>(),
                                              It.IsAny <string>(),
                                              It.IsAny <SortOrder>(),
                                              It.IsAny <int>(),
                                              It.IsAny <int>()
                                              )).Returns(requestsProgressBySchoolLinqed);
            var responseModel = new List <TranscriptRequestProgressResponseModel>
            {
                new TranscriptRequestProgressResponseModel
                {
                    Id                            = 1234,
                    AvatarUrl                     = "http://www.avatar.com/avatar.jpg",
                    StudentName                   = "FirstName, LastName",
                    DateOfBirth                   = new DateTime(2000, 5, 23),
                    GradeId                       = 11,
                    GradeKey                      = "GRADE_11",
                    StudentId                     = "1234",
                    TranscriptRequestId           = 12,
                    InunId                        = "1234",
                    ReceivingInstitutionCode      = 1234,
                    ReceivingInstitutionName      = "Institution Name",
                    ReceivingInstitutionCity      = "City",
                    ReceivingInstitutionStateCode = "SC",
                    RequestedDate                 = new DateTime(),
                    TranscriptStatus              = TranscriptRequestStatus.Submitted,
                    TranscriptStatusKey           = "SUBMITTED",
                    TranscriptStatusDate          = new DateTime()
                }
            };

            _mockTranscriptRequestService.Setup(rs => rs.GetTranscriptRequestProgressResponseModelAsync(It.IsAny <List <TranscriptRequestProgressViewModel> >(), It.IsAny <int>())).ReturnsAsync(responseModel);

            // Act
            var actionResult = await CreateController().GetTranscriptRequestProgressForCurrentSchool();

            //Assert
            var contentResult = new OkObjectResult(actionResult);

            Assert.AreEqual(StatusCodes.Status200OK, contentResult.StatusCode);
            var response = Result <ItemsCountModel <TranscriptRequestProgressResponseModel> >(actionResult);

            Assert.IsNotNull(response);
            var expected = new ItemsCountModel <TranscriptRequestProgressResponseModel>
            {
                Items = responseModel,
                Count = 1
            };

            CollectionAssert.AreEquivalent(expected.Items.ToList(), response.Items.ToList());
            Assert.AreEqual(expected.Count, response.Count);
        }
Esempio n. 30
0
 public void CreateInstitution(InstitutionModel model)
 {
     _institutionRepository.Add(model.ToEntity());
 }