Example #1
0
        public static Image UploadImg(HttpRequestBase request, Image img = null)
        {
            var file = request.Files["attachments"];


            if (img == null)
            {
                img = new Image();
            }
            if (file != null && !string.IsNullOrWhiteSpace(file.FileName))
            {
                byte[] buf = new byte[file.ContentLength];

                file.InputStream.Read(buf, 0, file.ContentLength);
                img.ImageData   = buf;
                img.ContentType = file.ContentType;
            }

            if (img.ID > 0)
            {
                if (file == null)
                {
                    var old = CH.DB.Images.AsNoTracking().FirstOrDefault(i => i.ID == img.ID);
                    img.ImageData   = old.ImageData;
                    img.ContentType = old.ContentType;
                }

                CH.Edit <Image>(img);
            }
            else
            {
                CH.Create <Image>(img);
            }
            return(img);
        }
Example #2
0
        public static void SyncUser()
        {
            foreach (MembershipUser item in Membership.GetAllUsers())
            {
                if (CH.DB.EmployeeRoles.Where(s => s.AccountName == item.UserName).Any())
                {
                    ProfileBase  objProfile = ProfileBase.Create(item.UserName);
                    EmployeeRole selUser    = CH.DB.EmployeeRoles.Where(s => s.AccountName == item.UserName).First();

                    selUser.IsActivated = (bool)objProfile.GetPropertyValue("IsActivated");
                    if (string.IsNullOrEmpty(selUser.Gender))
                    {
                        selUser.Gender = objProfile.GetPropertyValue("Gender") as string;
                    }
                    if (string.IsNullOrEmpty(selUser.AccountNameCN) || selUser.AccountNameCN == "-")
                    {
                        var v = objProfile.GetPropertyValue("DisplayName") as string;
                        if (!string.IsNullOrEmpty(v))
                        {
                            selUser.AccountNameCN = objProfile.GetPropertyValue("DisplayName") as string;
                        }
                    }
                    if (string.IsNullOrEmpty(selUser.Mobile))
                    {
                        selUser.Mobile = objProfile.GetPropertyValue("Mobile") as string;
                    }
                    if (selUser.AgentNum == null)
                    {
                        selUser.AgentNum = objProfile.GetPropertyValue("Contact") as int?;
                    }
                    if (selUser.DepartmentID == null)
                    {
                        selUser.DepartmentID = objProfile.GetPropertyValue("DepartmentID") as int?;
                    }
                    var sdstring = objProfile.GetPropertyValue("StartDate") as string;

                    selUser.BirthDay = objProfile.GetPropertyValue("BirthDay") as DateTime?;
                    DateTime sddate;
                    DateTime.TryParse(sdstring, out sddate);
                    if (sddate != DateTime.MinValue && sddate != null)
                    {
                        selUser.StartDate = sddate;
                    }
                    if (selUser.BirthDay == DateTime.MinValue)
                    {
                        selUser.BirthDay = null;
                    }
                    if (string.IsNullOrWhiteSpace(selUser.AccountNameCN))
                    {
                        selUser.AccountNameCN = "-";
                    }
                    CH.Edit <EmployeeRole>(selUser);
                }
            }
        }