public async Task <IActionResult> CreateResearcher([FromBody] ResearcherModel model)
        {
            if (!ModelState.IsValid)
            {
                return(new BadRequestObjectResult("Invalid model inputs"));
            }

            var command = new CreateResearcherCommand(model);

            var result = this._mediator.Send(command).Result;

            if (result == null)
            {
                return(new BadRequestObjectResult("Something went wrong"));
            }
            if (result.GetType() == typeof(bool) && (bool)result == false)
            {
                return(new BadRequestObjectResult("Something went wrong"));
            }
            if (result.GetType() == typeof(string))
            {
                return(new BadRequestObjectResult(result));
            }
            return(new OkObjectResult(result));
        }
        public virtual IActionResult Edit(ResearcherModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageResearchers))
            {
                return(AccessDeniedView());
            }

            //try to get a researcher with the specified id
            var  researcher = _researcherService.GetResearcherById(model.Id);
            bool active     = researcher.IsActive;
            bool completed  = researcher.IsCompleted;

            if (researcher == null)
            {
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                researcher             = model.ToEntity(researcher);
                researcher.IsActive    = active;
                researcher.IsCompleted = completed;
                if (model.ParseDateOfBirth() != null)
                {
                    researcher.Birthdate = model.ParseDateOfBirth();
                }

                _researcherService.UpdateResearcher(researcher);

                var address = model.AddressModel.ToEntity <Address>();
                SaveAddress(model.AddressModel, address);
                if (address.Id != 0)
                {
                    researcher.AddressId = address.Id;
                    _researcherService.UpdateResearcher(researcher);
                }

                SuccessNotification("Researcher Updated");

                //activity log
                //_userActivityService.InsertActivity("EditResearcher", "ActivityLog EditResearcher", researcher);

                if (!continueEditing)
                {
                    return(RedirectToAction("List"));
                }

                //selected tab
                SaveSelectedTabName();

                return(RedirectToAction("Edit", new { id = researcher.Id }));
            }

            //prepare model
            model = _researcherModelFactory.PrepareResearcherModel(model, researcher, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
        public ActionResult Create(ResearcherModel researcher)
        {
            try
            {
                researcherCollection.InsertOne(researcher);
                return(Content(JsonConvert.SerializeObject(researcher)));
            }

            catch (Exception e)
            {
                return(Content(JsonConvert.SerializeObject(e.Message)));
            }
        }
        public ActionResult Create(ResearcherModel researcher)
        {
            try
            {
                researcherCollection.InsertOne(researcher);
                return(View());
            }

            catch
            {
                return(null);
            }
        }
        public virtual IActionResult Create(ResearcherModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageResearchers))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var researcher = model.ToEntity <Researcher>();

                if (model.ParseDateOfBirth() != null)
                {
                    researcher.Birthdate = model.ParseDateOfBirth();
                }
                researcher.IsActive = true;
                _researcherService.InsertResearcher(researcher);

                var address = model.AddressModel.ToEntity <Address>();
                SaveAddress(model.AddressModel, address);
                if (address.Id != 0)
                {
                    researcher.AddressId = address.Id;
                    _researcherService.UpdateResearcher(researcher);
                }


                SuccessNotification("Admin.ContentManagement.Researchers.Added");

                //activity log
                //_userActivityService.InsertActivity("AddNewResearcher", "ActivityLog.AddNewResearcher", researcher);

                if (!continueEditing)
                {
                    return(RedirectToAction("List"));
                }

                //selected tab
                SaveSelectedTabName();

                return(RedirectToAction("Edit", new { id = researcher.Id }));
            }

            //prepare model
            model = _researcherModelFactory.PrepareResearcherModel(model, null, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
예제 #6
0
        public ActionResult ResearcherSearch()
        {
            ResearcherClient rc = new ResearcherClient();
            var searchData      = rc.GetSearchData();

            if (!searchData.Succeeded)
            {
                ViewBag.ErrorMessage = searchData.ErrorMessages;
                return(View());
            }
            else
            {
                ResearcherModel c = new ResearcherModel();
                c.PatientFields       = searchData.PatientTags;
                c.QuestionnaireFields = searchData.QuestionnaireNames;
                return(View(c));
            }
        }
        public ActionResult Edit(ResearcherModel researcher)
        {
            try
            {
                var filter = Builders <ResearcherModel> .Filter.Eq("_id", researcher.Id);

                var update = Builders <ResearcherModel> .Update
                             .Set("Email", researcher.Email)
                             .Set("Degree", researcher.Degree);

                var result = researcherCollection.UpdateOne(filter, update);
                return(Content(JsonConvert.SerializeObject(researcher)));
            }

            catch (Exception e)
            {
                return(Content(JsonConvert.SerializeObject(e.Message)));
            }
        }
        public ActionResult Edit(ResearcherModel researcher)
        {
            try
            {
                var filter = Builders <ResearcherModel> .Filter.Eq("_id", researcher.Id);

                var update = Builders <ResearcherModel> .Update
                             .Set("Email", researcher.Email)
                             .Set("Degree", researcher.Degree);

                var result = researcherCollection.UpdateOne(filter, update);
                return(View());
            }

            catch
            {
                return(null);
            }
        }
예제 #9
0
        public ActionResult Login([FromBody] LoginModel loginModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            using TrackerContext db = new();
            Researcher researcher = db.Researcher.FirstOrDefault(r =>
                                                                 (r.Email.Equals(loginModel.EmailOrPhoneNumber) ||
                                                                  r.PhoneNumber.Equals(loginModel.EmailOrPhoneNumber)) &&
                                                                 r.Password.Equals(loginModel.Password)
                                                                 );

            if (researcher != null)
            {
                string token = string.Empty;
                do
                {
                    token = TokenManagement.GenerateToken();
                } while (db.UserToken.FirstOrDefault(t => t.Token.Equals(token)) != null);
                UserToken ut = new () {
                    ResearcherID = researcher.ID,
                    Token        = token
                };
                db.UserToken.Add(ut);
                db.SaveChanges();
                var researcherModel = new ResearcherModel()
                {
                    Nickname    = researcher.Nickname,
                    Email       = researcher.Email,
                    PhoneNumber = researcher.PhoneNumber,
                    ID          = researcher.ID,
                    Token       = token
                };
                return(Ok(researcherModel));
            }

            return(BadRequest("Login attempt failed"));
        }
        public async Task <IActionResult> UpdateResearcher([FromBody] ResearcherModel model)
        {
            if (model.ResearcherName == null && model.ResearcherId <= 0)
            {
                return(new BadRequestObjectResult("somerhing went wrong"));
            }

            UpdateResearcherCommand command = new UpdateResearcherCommand(model);

            var result = await this._mediator.Send(command);

            if (result == null)
            {
                return(new BadRequestObjectResult("Could not update reseacher"));
            }
            if (result.GetType() == typeof(bool) && (bool)result == false)
            {
                return(new BadRequestObjectResult("Something went wrong"));
            }

            return(new OkObjectResult(result));
        }
예제 #11
0
        public ActionResult ResearcherSearch(string modelSubmit)
        {
            ViewBag.model = modelSubmit;
            //var x2 = System.Web.Helpers.Json.Decode(modelSubmit);
            var group           = new System.Web.Script.Serialization.JavaScriptSerializer(new ResearcherModelResolver()).Deserialize <group>(modelSubmit);
            ResearcherClient rc = new ResearcherClient();
            var result          = rc.Search(this.ProcessGroup(group));

            if (!result.Succeeded)
            {
                ViewBag.ErrorMessage = result.ErrorMessages;
                return(View());
            }

            var             searchData = rc.GetSearchData();
            ResearcherModel c          = new ResearcherModel();

            c.PatientFields       = searchData.PatientTags;
            c.QuestionnaireFields = searchData.QuestionnaireNames;

            StringBuilder output = new StringBuilder();

            output.Append("<table>");
            output.Append("<tr><th>Patient Id</th><th>Response Group Id</th><th>Start Time</th><th>End Time</th></tr>");
            foreach (var responses in result.QuestionnaireUserResponseGroups)
            {
                output.Append("<tr>");
                output.Append("<td>").Append(responses.Patient.Id).Append("</td>");
                output.Append("<td>").Append(responses.Id).Append("</td>");
                output.Append("<td>").Append(responses.StartTime.Value.ToString("yyyy-MM-dd HH:mm:ss")).Append("</td>");
                output.Append("<td>").Append(responses.DateTimeCompleted.Value.ToString("yyyy-MM-dd HH:mm:ss")).Append("</td>");
                output.Append("</tr>");
            }
            output.Append("</table>");
            ViewBag.Result = output.ToString();

            return(View(c));
        }
예제 #12
0
 public UpdateResearcherCommand(ResearcherModel model)
 {
     this.Model = model;
 }
예제 #13
0
        /// <summary>
        /// Prepare researcher model
        /// </summary>
        /// <param name="model">Researcher model</param>
        /// <param name="researcher">Researcher</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Researcher model</returns>
        public virtual ResearcherModel PrepareResearcherModel(ResearcherModel model, Researcher researcher, bool excludeProperties = false)
        {
            if (researcher != null)
            {
                //fill in model values from the entity
                model = model ?? researcher.ToModel <ResearcherModel>();
                model.ResearcherCode   = researcher.ResearcherCode;
                model.TitleId          = researcher.TitleId;
                model.FirstName        = researcher.FirstName;
                model.LastName         = researcher.LastName;
                model.FirstNameEN      = researcher.FirstNameEN;
                model.LastNameEN       = researcher.LastNameEN;
                model.DateOfBirthDay   = researcher.Birthdate?.Day;
                model.DateOfBirthMonth = researcher.Birthdate?.Month;
                model.DateOfBirthYear  = researcher.Birthdate?.Year;
                model.IDCard           = researcher.IDCard;
                model.Telephone        = researcher.Telephone;
                model.Email            = researcher.Email;
                model.PictureId        = researcher.PictureId;
                model.PersonalTypeId   = researcher.PersonalTypeId;
                model.AgencyId         = researcher.AgencyId;
                model.AcademicRankId   = researcher.AcademicRankId;
                model.IsActive         = researcher.IsActive;
                if (researcher.Birthdate.HasValue)
                {
                    model.DateOfBirthDay   = researcher.Birthdate.Value.Day;
                    model.DateOfBirthMonth = researcher.Birthdate.Value.Month;
                    model.DateOfBirthYear  = researcher.Birthdate.Value.Year + 543;
                    model.DateOfBirthName  = CommonHelper.ConvertToThaiDate(researcher.Birthdate.Value);
                }

                PrepareResearcherEducationSearchModel(model.ResearcherEducationSearchModel, researcher);
                model.AcademicRankName             = researcher.AcademicRank != null ? researcher.AcademicRank.NameTh : string.Empty;
                model.PersonalTypeName             = researcher.PersonalType.GetAttributeOfType <EnumMemberAttribute>().Value;
                model.ResearcherEducationListModel = PrepareResearcherEducationListModel(new ResearcherEducationSearchModel {
                    ResearcherId = researcher.Id
                }, researcher);
            }
            else
            {
                model.ResearcherCode = _researcherService.GetNextNumber();
            }
            PrepareAddressModel(model.AddressModel, researcher);
            _baseAdminModelFactory.PrepareTitles(model.AvailableTitles, true, "--ระบุคำนำหน้าชื่อ--");
            _baseAdminModelFactory.PrepareAgencies(model.AvailableAgencies, true, "--ระบุประเภทหน่วยงาน--");
            _baseAdminModelFactory.PreparePersonalTypes(model.AvailablePersonalTypes, true, "--ระบุประเภทบุคลากร--");
            int personType = 1;

            if (model.PersonalTypeId != 0)
            {
                personType = model.PersonalTypeId;
            }
            _baseAdminModelFactory.PrepareAcademicRanks(model.AvailableAcademicRanks, personType, true, "--ระบุตำแหน่งวิชาการ--");

            _baseAdminModelFactory.PrepareDegrees(model.AvailableAddEducationDegrees, true, "--ระบุระดับปริญญา--");
            _baseAdminModelFactory.PrepareEducationLevels(model.AvailableAddEducationEducationLevels, true, "--ระบุวุฒิการศึกษา--");
            _baseAdminModelFactory.PrepareInstitutes(model.AvailableAddEducationInstitutes, true, "--ระบุสถาบันการศึกษา--");
            _baseAdminModelFactory.PrepareCountries(model.AvailableAddEducationCountries, true, "--ระบุประเทศ--");
            //Default Thailand
            model.AddEducationCountryId      = 229;
            model.AddEducationGraduationYear = DateTime.Now.Year + 543;
            return(model);
        }