Пример #1
0
        public IActionResult Record(int pid, bool isclone)
        {
            if (!this.TestIfUserEditor(true, true))
            {
                return(this.StopPageCreateEdit(true));
            }
            var v = new Models.j02RecordViewModel();

            if (pid > 0)
            {
                v.Rec = Factory.j02PersonBL.Load(pid);
                if (v.Rec == null)
                {
                    return(RecNotFound(v));
                }
                if (!this.TestIfRecordEditable(v.Rec.j02ID_Owner))
                {
                    return(this.StopPageEdit(true));
                }
                if (v.Rec.j03ID > 0)
                {
                    v.UserProfile   = Factory.j03UserBL.Load(v.Rec.j03ID);
                    v.IsUserProfile = true;
                }
                else
                {
                    v.UserProfile = new BO.j03User();
                }
                var tg = Factory.o51TagBL.GetTagging("j02", pid);
                v.TagPids  = tg.TagPids;
                v.TagNames = tg.TagNames;
                v.TagHtml  = tg.TagHtml;
            }
            else
            {
                v.Rec         = new BO.j02Person();
                v.Rec.entity  = "j02";
                v.UserProfile = new BO.j03User();
            }

            RefreshState(v);
            if (isclone)
            {
                v.Toolbar.MakeClone();
            }


            return(View(v));
        }
Пример #2
0
        public IActionResult Record(Models.j02RecordViewModel v)
        {
            if (ModelState.IsValid)
            {
                BO.j02Person c = new BO.j02Person();

                if (v.Rec.pid > 0)
                {
                    c = Factory.j02PersonBL.Load(v.Rec.pid);
                }

                c.p28ID = v.Rec.p28ID;
                c.j02TitleBeforeName = v.Rec.j02TitleBeforeName;
                c.j02TitleAfterName  = v.Rec.j02TitleAfterName;
                c.j02FirstName       = v.Rec.j02FirstName;
                c.j02LastName        = v.Rec.j02LastName;
                c.j02Email           = v.Rec.j02Email;
                c.j02Tel1            = v.Rec.j02Tel1;
                c.j02Tel2            = v.Rec.j02Tel2;
                c.j02JobTitle        = v.Rec.j02JobTitle;
                c.j02ID_Owner        = v.Rec.j02ID_Owner;

                c.ValidUntil = v.Toolbar.GetValidUntil(c);
                c.ValidFrom  = v.Toolbar.GetValidFrom(c);

                if (ValidateBeforeSave(c, v))
                {
                    v.Rec.pid = Factory.j02PersonBL.Save(c);
                    if (v.Rec.pid > 0)
                    {
                        Factory.o51TagBL.SaveTagging("j02", v.Rec.pid, v.TagPids);

                        c = Factory.j02PersonBL.Load(v.Rec.pid);
                        if (v.IsUserProfile == false)
                        {
                            v.SetJavascript_CallOnLoad(v.Rec.pid);
                            return(View(v));
                        }
                    }

                    if (c.pid > 0 && v.IsUserProfile == true)
                    {
                        BO.j03User cU = new BO.j03User();

                        cU.j02ID = c.pid;
                        if (c.j03ID > 0)
                        {
                            cU = Factory.j03UserBL.Load(c.j03ID);
                        }
                        cU.j04ID    = v.UserProfile.j04ID;
                        cU.j03Login = v.UserProfile.j03Login;
                        cU.j03IsMustChangePassword = v.UserProfile.j03IsMustChangePassword;
                        cU.ValidUntil = c.ValidUntil;
                        if (c.j03ID == 0)
                        {
                            var recJ04 = Factory.j04UserRoleBL.Load(cU.j04ID);
                            if (recJ04.j04IsClientRole)
                            {
                                cU.j03EnvironmentFlag = 2;  //client prostředí
                            }
                            else
                            {
                                cU.j03EnvironmentFlag = 1;  //master prostředí
                            }
                        }

                        if (!string.IsNullOrEmpty(v.ResetPassword))
                        {
                            var lu = new BO.LoggingUser();
                            cU.j03PasswordHash = lu.Pwd2Hash(v.ResetPassword, cU);
                        }
                        int intJ03ID = Factory.j03UserBL.Save(cU);
                        if (intJ03ID > 0)
                        {
                            if (cU.j03ID == 0)  //nahodit první heslo pro nového uživatele
                            {
                                cU = Factory.j03UserBL.Load(intJ03ID);
                                var lu = new BO.LoggingUser();
                                cU.j03PasswordHash = lu.Pwd2Hash(v.ResetPassword, cU);
                                Factory.j03UserBL.Save(cU);
                            }
                            v.SetJavascript_CallOnLoad(v.Rec.pid);
                            return(View(v));
                        }
                    }
                }
            }

            RefreshState(v);
            this.Notify_RecNotSaved();
            return(View(v));
        }