Beispiel #1
0
        public BsJsonResult GetEditableContent(long objId, PanelComponentsEnum componentId)
        {
            var html  = string.Empty;
            var model = _userProfileRepository.GetEditableUserProfile(objId, componentId);

            switch (componentId)
            {
            case PanelComponentsEnum.UserInfo:
            {
                html = this.BsRenderPartialView("Editable/_UserInfo", model.UserInfo, model.GetPropertyName(x => x.UserInfo));
                break;
            }

            case PanelComponentsEnum.Contact:
            {
                html = this.BsRenderPartialView("Editable/_Contact", model.Contact, model.GetPropertyName(x => x.Contact));
                break;
            }
            }

            return(new BsJsonResult(new
            {
                Html = html
            }));
        }
Beispiel #2
0
        public UserProfileEditableModel GetEditableUserProfile(long objId, PanelComponentsEnum componentId)
        {
            var model  = db.Users.FirstOrDefault(x => x.Id == objId);
            var result = new UserProfileEditableModel
            {
                Id      = model.Id,
                Contact = new UserProfileContactEditableModel
                {
                    Email = model.Email
                }
            };

            if (componentId == PanelComponentsEnum.Contact)
            {
                var profile = model.UsersProfiles.FirstOrDefault();
                if (profile != null && profile.Address != null)
                {
                    result.Contact.PhoneNumber     = profile.PhoneNumber;
                    result.Contact.PhysicalAddress = profile.Address.PhysicalAddress;
                }
            }
            else if (componentId == PanelComponentsEnum.UserInfo)
            {
                var profile = model.UsersProfiles.FirstOrDefault();
                if (profile != null)
                {
                    var states = new BsSelectList <int?>
                    {
                        Items = db.UsersStates.Select(x => new BsSelectListItem
                        {
                            Text  = x.Code,
                            Value = x.Id.ToString()
                        }).ToList(),
                        SelectedValues = profile.Id_State
                    };

                    result.UserInfo = new UserProfileInfoEditableModel
                    {
                        Firstname = model.Firstname,
                        Lastname  = model.Lastname,
                        BirthDay  = new BsDateTime
                        {
                            DateValue = profile.Birthday
                        },
                        Profession    = profile.Profession,
                        StateDropdown = states
                    };
                }
            }

            return(result);
        }
Beispiel #3
0
        public BsJsonResult SetContent(UserProfileEditableModel model, PanelComponentsEnum componentId, long objId)
        {
            var msg    = string.Empty;
            var status = BsResponseStatus.Success;
            var html   = string.Empty;

            if (ModelState.IsValid)
            {
                var profileModel = _userProfileRepository.Update(model, objId);
                switch (componentId)
                {
                case PanelComponentsEnum.UserInfo:
                    html = this.BsRenderPartialView("Readonly/_UserInfo", profileModel.UserInfo);
                    break;

                case PanelComponentsEnum.Contact:
                    html = this.BsRenderPartialView("Readonly/_Contact", profileModel.Contact);
                    break;
                }
            }
            else
            {
                return(new BsJsonResult(
                           new Dictionary <string, object> {
                    { "Errors", ModelState.GetErrors() }
                },
                           BsResponseStatus.ValidationError));
            }

            var userData = Session["UserData"] as UserData;

            if (userData != null)
            {
                var cnp = userData.CNP;
                Session["UserData"] = new UserData(HesiraDB, cnp);
            }

            return(new BsJsonResult(
                       new
            {
                Html = html,
            },
                       status,
                       msg));
        }
        public BsJsonResult GetEditableContent(PanelComponentsEnum componentId)
        {
            var html = string.Empty;
            var model = GetUserProfileModelEditable();

            switch (componentId)
            {
                case PanelComponentsEnum.UserInfo:
                    html = this.BsRenderPartialView("Editable/_UserInfo", model.UserInfo, model.GetPropertyName(x => x.UserInfo));
                    break;
                case PanelComponentsEnum.Contact:
                    html = this.BsRenderPartialView("Editable/_Contact", model.Contact, model.GetPropertyName(x => x.Contact));
                    break;
            }

            return new BsJsonResult(new
            {
                Html = html
            });
        }
        public BsJsonResult GetEditableContent(PanelComponentsEnum componentId)
        {
            var html  = string.Empty;
            var model = GetUserProfileModelEditable();

            switch (componentId)
            {
            case PanelComponentsEnum.UserInfo:
                html = this.BsRenderPartialView("Editable/_UserInfo", model.UserInfo, model.GetPropertyName(x => x.UserInfo));
                break;

            case PanelComponentsEnum.Contact:
                html = this.BsRenderPartialView("Editable/_Contact", model.Contact, model.GetPropertyName(x => x.Contact));
                break;
            }

            return(new BsJsonResult(new
            {
                Html = html
            }));
        }
        public BsJsonResult GetReadonlyContent(PanelComponentsEnum componentId)
        {
            var html = string.Empty;
            var msg = string.Empty;
            var status = BsResponseStatus.Success;

            try
            {
                switch (componentId)
                {
                    case PanelComponentsEnum.UserInfo:

                        var userInfo = GetUserProfileModel().UserInfo;

                        var passwordRegex = new Regex(".");
                        userInfo.Password = passwordRegex.Replace(userInfo.Password, "*");

                        html = this.BsRenderPartialView("Readonly/_UserInfo", GetUserProfileModel().UserInfo);
                        break;

                    case PanelComponentsEnum.Contact:
                        html = this.BsRenderPartialView("Readonly/_Contact", GetUserProfileModel().Contact);
                        break;
                }

            }

            catch (Exception ex)
            {
                msg = ex.Message;
                status = BsResponseStatus.ServerError;
            }

            return new BsJsonResult(new
            {
                Html = html
            }, status, msg);
        }
        public BsJsonResult GetReadonlyContent(PanelComponentsEnum componentId)
        {
            var html   = string.Empty;
            var msg    = string.Empty;
            var status = BsResponseStatus.Success;

            try
            {
                switch (componentId)
                {
                case PanelComponentsEnum.UserInfo:

                    var userInfo = GetUserProfileModel().UserInfo;

                    var passwordRegex = new Regex(".");
                    userInfo.Password = passwordRegex.Replace(userInfo.Password, "*");

                    html = this.BsRenderPartialView("Readonly/_UserInfo", GetUserProfileModel().UserInfo);
                    break;

                case PanelComponentsEnum.Contact:
                    html = this.BsRenderPartialView("Readonly/_Contact", GetUserProfileModel().Contact);
                    break;
                }
            }

            catch (Exception ex)
            {
                msg    = ex.Message;
                status = BsResponseStatus.ServerError;
            }

            return(new BsJsonResult(new
            {
                Html = html
            }, status, msg));
        }
Beispiel #8
0
        public BsJsonResult GetReadonlyContent(long objId, PanelComponentsEnum componentId)
        {
            var html   = string.Empty;
            var msg    = string.Empty;
            var status = BsResponseStatus.Success;

            try
            {
                switch (componentId)
                {
                case PanelComponentsEnum.UserInfo:
                {
                    var userInfoModel = _userProfileRepository.GetUserProfile(objId).UserInfo;
                    html = this.BsRenderPartialView("Readonly/_UserInfo", userInfoModel);
                    break;
                }

                case PanelComponentsEnum.Contact:
                {
                    var userContactModel = _userProfileRepository.GetUserProfile(objId).Contact;
                    html = this.BsRenderPartialView("Readonly/_Contact", userContactModel);
                    break;
                }
                }
            }

            catch (Exception ex)
            {
                msg    = ex.Message;
                status = BsResponseStatus.ServerError;
            }

            return(new BsJsonResult(new
            {
                Html = html
            }, status, msg));
        }
        public BsJsonResult SetContent(UserProfileEditableModel model, PanelComponentsEnum componentId)
        {
            var html   = string.Empty;
            var status = BsResponseStatus.Success;
            var msg    = string.Empty;

            switch (componentId)
            {
            case PanelComponentsEnum.UserInfo:
                ModelState.ClearModelState(model.GetPropertyName(m => m.UserInfo) + ".");
                break;

            case PanelComponentsEnum.Contact:
                ModelState.ClearModelState(model.GetPropertyName(m => m.Contact) + ".");
                break;
            }

            try
            {
                if (ModelState.IsValid)
                {
                    var profileModel = GetUserProfileModel();

                    switch (componentId)
                    {
                    case PanelComponentsEnum.UserInfo:

                        var dateValue = model.UserInfo.HireDate.DateValue.Value;

                        if (dateValue.Year == 2014 && dateValue.Day == 1 && dateValue.Month == 1)
                        {
                            throw new Exception("This is how an exception message is displayed inside a panel");
                        }

                        profileModel.UserInfo.Firstname = model.UserInfo.Firstname;
                        profileModel.UserInfo.Lastname  = model.UserInfo.Lastname;
                        profileModel.UserInfo.Password  = model.UserInfo.Password;
                        profileModel.UserInfo.HireDate  = model.UserInfo.HireDate.DateValue.Value;
                        profileModel.Basic.Username     = model.UserInfo.Firstname + " " + model.UserInfo.Lastname;

                        SaveUserProfileModel(profileModel);

                        var passwordRegex = new Regex(".");
                        profileModel.UserInfo.Password = passwordRegex.Replace(profileModel.UserInfo.Password, "*");

                        html = this.BsRenderPartialView("Readonly/_UserInfo", profileModel.UserInfo);

                        return(new BsJsonResult(new
                        {
                            Html = html,
                            Username = profileModel.Basic.Username
                        }));

                        break;

                    case PanelComponentsEnum.Contact:
                        profileModel.Contact.Mail    = model.Contact.Mail;
                        profileModel.Contact.Website = model.Contact.Website;

                        SaveUserProfileModel(profileModel);


                        html = this.BsRenderPartialView("Readonly/_Contact", profileModel.Contact);

                        break;
                    }
                }
                else
                {
                    //JSON serialize ModelState errors
                    return(new BsJsonResult(
                               new Dictionary <string, object> {
                        { "Errors", ModelState.GetErrors() }
                    },
                               BsResponseStatus.ValidationError));
                }
            }

            catch (Exception ex)
            {
                msg    = "<strong>" + Resource.ServerError + "!</strong> " + ex.Message;
                status = BsResponseStatus.ServerError;
            }

            return(new BsJsonResult(new
            {
                Html = html
            }, status, msg));
        }
        public BsJsonResult SetContent(UserProfileEditableModel model, PanelComponentsEnum componentId)
        {
            var html = string.Empty;
            var status = BsResponseStatus.Success;
            var msg = string.Empty;

            switch (componentId)
            {
                case PanelComponentsEnum.UserInfo:
                    ModelState.ClearModelState(model.GetPropertyName(m => m.UserInfo) + ".");
                    break;

                case PanelComponentsEnum.Contact:
                    ModelState.ClearModelState(model.GetPropertyName(m => m.Contact) + ".");
                    break;
            }

            try
            {

                if (ModelState.IsValid)
                {
                    var profileModel = GetUserProfileModel();

                    switch (componentId)
                    {
                        case PanelComponentsEnum.UserInfo:

                            var dateValue = model.UserInfo.HireDate.DateValue.Value;

                            if (dateValue.Year == 2014 && dateValue.Day == 1 && dateValue.Month == 1)
                            {
                                throw new Exception("This is how an exception message is displayed inside a panel");
                            }

                            profileModel.UserInfo.Firstname = model.UserInfo.Firstname;
                            profileModel.UserInfo.Lastname = model.UserInfo.Lastname;
                            profileModel.UserInfo.Password = model.UserInfo.Password;
                            profileModel.UserInfo.HireDate = model.UserInfo.HireDate.DateValue.Value;
                            profileModel.Basic.Username = model.UserInfo.Firstname + " " + model.UserInfo.Lastname;

                            SaveUserProfileModel(profileModel);

                            var passwordRegex = new Regex(".");
                            profileModel.UserInfo.Password = passwordRegex.Replace(profileModel.UserInfo.Password, "*");

                            html = this.BsRenderPartialView("Readonly/_UserInfo", profileModel.UserInfo);

                            return new BsJsonResult(new
                            {
                                Html = html,
                                Username = profileModel.Basic.Username
                            });

                            break;

                        case PanelComponentsEnum.Contact:
                            profileModel.Contact.Mail = model.Contact.Mail;
                            profileModel.Contact.Website = model.Contact.Website;

                            SaveUserProfileModel(profileModel);

                            html = this.BsRenderPartialView("Readonly/_Contact", profileModel.Contact);

                            break;
                    }

                }
                else
                {
                    //JSON serialize ModelState errors
                    return new BsJsonResult(
                        new Dictionary<string, object> {{"Errors", ModelState.GetErrors()}},
                        BsResponseStatus.ValidationError);
                }

            }

            catch (Exception ex)
            {
                msg = "<strong>" + Resource.ServerError + "!</strong> " + ex.Message;
                status = BsResponseStatus.ServerError;
            }

            return new BsJsonResult(new
            {
                Html = html
            },status,msg);
        }