Beispiel #1
0
        public static Role GetRole(string name)
        {
            var roles = from e in CH.DB.EmployeeRoles
                        from r in CH.DB.Roles
                        where e.AccountName == name && e.RoleID == r.ID

                        select r;

            if (roles.FirstOrDefault() != null)
            {
                return(roles.FirstOrDefault());
            }
            else
            {
                var roleid = GetProfile("RoleLevelID", name).ToString();
                int id;
                int.TryParse(roleid, out id);
                var role = CH.GetDataById <Role>(id);
                if (role != null)
                {
                    var emp = new EmployeeRole()
                    {
                        RoleID = role.ID, AccountName = name, CreatedDate = DateTime.Now
                    };
                    CH.DB.Set <EmployeeRole>().Add(emp);
                    CH.DB.SaveChanges();
                }
                return(role);
            }
        }
Beispiel #2
0
        public static List <SelectListItem> LeadSelectListByCRMID(int?crmid, int?selectVal = null)
        {
            if (crmid == null)
            {
                return(new List <SelectListItem>());
            }

            int?companyid = CH.GetDataById <CompanyRelationship>(crmid).CompanyID;
            //var ls = from l in CH.DB.Leads where l.CompanyID == companyid select new { Text = l.Name_CH + " | " + l.Name_EN, Value = l.ID };
            List <SelectListItem> selectList = new List <SelectListItem>();
            var leads = from c in CH.DB.Leads where c.CompanyID == companyid select c;

            //CH.GetAllData<Lead>().Where(l => l.CompanyID == companyid);
            foreach (Lead lead in leads)
            {
                SelectListItem selectListItem = new SelectListItem {
                    Text = lead.Name, Value = lead.ID.ToString()
                };
                if (selectVal.HasValue && lead.ID == selectVal.Value)
                {
                    selectListItem.Selected = true;
                }
                selectList.Add(selectListItem);
            }
            return(selectList);
        }
Beispiel #3
0
        public ActionResult DisplayImage(int id)
        {
            var image = CH.GetDataById <Image>(id);

            if (image != null)
            {
                byte[] imageData = image.ImageData;
                if (imageData == null)
                {
                    return(null);
                }
                return(File(imageData, image.ContentType));
            }
            return(null);
        }
Beispiel #4
0
        public static IEnumerable <SelectListItem> CompanyLeadsSelectList(int companyid, int?selectVal = null)
        {
            List <SelectListItem> selectList = new List <SelectListItem>();
            //var query = from c in CH.DB.CompanyRelationships.Where(w => w.Project.ID == projectid && w.Company.ID == companyid) select c.Company.Leads;
            //var leads = CH.GetAllData<Lead>().Where(l => l.CompanyID == companyid);
            var leads = CH.GetDataById <Company>(companyid).Leads;

            foreach (Lead lead in leads)
            {
                SelectListItem selectListItem = new SelectListItem {
                    Text = lead.Name, Value = lead.ID.ToString()
                };
                if (selectVal.HasValue && lead.ID == selectVal.Value)
                {
                    selectListItem.Selected = true;
                }
                selectList.Add(selectListItem);
            }
            return(selectList);
        }