Пример #1
0
        public async Task <UserProfile> Login(UserLoginProxy model)
        {
            if (ModelState.IsValid)
            {
                var u = await this._applicationUserServices.VerifyAndGetUser(model.UserName, model.Password);

                var selectedRoleName = this._applicationUserServices.GetRolesByUserName(u.UserName).FirstOrDefault();
                var data             = u.ToUserProfileViewModel(selectedRoleName, this._configurationRepository.DefaultUserImage);
                if (data.SelectedRoleName == "Parent")
                {
                    var c = this._referenceUserService.GetReferenceUserByParentId(data.Id);
                    if (c != null)
                    {
                        var child = this._applicationUserServices.FindById(c.ChildId);
                        data.Child         = child.ToUserProfileViewModel("Student", null);
                        data.Child.Approve = c.Approved;
                        if (model.Language.Equals("en"))
                        {
                            data.ReferenceUserName = string.Format("{0} {1}", child.FirstName_EN, child.LastName_EN);
                        }
                        else
                        {
                            data.ReferenceUserName = string.Format("{0} {1}", child.FirstName_TH, child.LastName_TH);
                        }
                    }
                }
                else if (data.SelectedRoleName == "Student")
                {
                    var p = this._referenceUserService.GetReferenceUserByChildId(data.Id);
                    if (p != null)
                    {
                        var parent = this._applicationUserServices.FindById(p.ParentId);
                        data.Parent         = parent.ToUserProfileViewModel("Parent", null);
                        data.Parent.Approve = p.Approved;
                        if (model.Language.Equals("en"))
                        {
                            data.ReferenceUserName = string.Format("{0} {1}", parent.FirstName_EN, parent.LastName_EN);
                        }
                        else
                        {
                            data.ReferenceUserName = string.Format("{0} {1}", parent.FirstName_TH, parent.LastName_TH);
                        }
                    }
                }
                return(data);
            }
            return(null);
        }
Пример #2
0
 public static ApplicationUser ToEntity(this UserLoginProxy data)
 {
     return(Mapper.Map <ApplicationUser>(data));
 }