Esempio n. 1
0
        public static IList <BudTemplate> Select(int pagesize, int pageIndex, string tempTypeId)
        {
            IList <BudTemplate> list = new List <BudTemplate>();

            using (pm2Entities entities = new pm2Entities())
            {
                var queryable = (from temp in entities.Bud_Template
                                 where temp.Bud_TemplateType.TypeId == tempTypeId
                                 orderby temp.InputDate descending
                                 select new { TemplateId = temp.TemplateId, TemplateName = temp.TemplateName, TypeId = temp.Bud_TemplateType.TypeId }).Skip((pageIndex * pagesize)).Take(pagesize);
                if ((tempTypeId == "") || (tempTypeId == "0"))
                {
                    queryable = (from temp in entities.Bud_Template
                                 orderby temp.InputDate descending
                                 select new { TemplateId = temp.TemplateId, TemplateName = temp.TemplateName, TypeId = temp.Bud_TemplateType.TypeId }).Skip((pageIndex * pagesize)).Take(pagesize);
                }
                foreach (var typeb in queryable)
                {
                    BudTemplate item = new BudTemplate {
                        Id          = typeb.TemplateId,
                        Name        = typeb.TemplateName,
                        BudTempType = BudTemplateType.GetById(typeb.TypeId)
                    };
                    list.Add(item);
                }
            }
            return(list);
        }
Esempio n. 2
0
        public static IList <BudTemplate> GetAll(string templateTypeId)
        {
            var predicate            = null;
            IList <BudTemplate> list = new List <BudTemplate>();

            using (pm2Entities entities = new pm2Entities())
            {
                var source = (from bt in entities.Bud_Template
                              orderby bt.InputDate descending
                              select new { TemplateId = bt.TemplateId, TemplateCode = bt.TemplateCode, TemplateName = bt.TemplateName, InputUser = bt.InputUser, InputDate = bt.InputDate, TypeId = bt.Bud_TemplateType.TypeId }).ToList();
                if (!string.IsNullOrEmpty(templateTypeId))
                {
                    if (predicate == null)
                    {
                        predicate = m => m.TypeId == templateTypeId;
                    }
                    source = source.Where(predicate).ToList();
                }
                foreach (var typea in source)
                {
                    BudTemplate item = new BudTemplate {
                        Id          = typea.TemplateId,
                        Code        = typea.TemplateCode,
                        Name        = typea.TemplateName,
                        InputUser   = typea.InputUser,
                        InputDate   = new DateTime?(typea.InputDate),
                        BudTempType = BudTemplateType.GetById(typea.TypeId)
                    };
                    list.Add(item);
                }
            }
            return(list);
        }
Esempio n. 3
0
 public static void Update(BudTemplate budTemplate)
 {
     using (pm2Entities entities = new pm2Entities())
     {
         Bud_Template template = entities.Bud_Template.FirstOrDefault <Bud_Template>(c => c.TemplateId == budTemplate.Id);
         template.TemplateCode     = budTemplate.Code;
         template.TemplateName     = budTemplate.Name;
         template.Bud_TemplateType = entities.Bud_TemplateType.FirstOrDefault <Bud_TemplateType>(c => c.TypeId == budTemplate.BudTempType.Id);
         entities.SaveChanges();
     }
 }
Esempio n. 4
0
 public static void Add(BudTemplate budTemplate)
 {
     using (pm2Entities entities = new pm2Entities())
     {
         Bud_Template entity = new Bud_Template {
             TemplateId   = budTemplate.Id,
             TemplateCode = budTemplate.Code,
             TemplateName = budTemplate.Name,
             InputUser    = budTemplate.InputUser
         };
         if (budTemplate.InputDate.HasValue)
         {
             entity.InputDate = Convert.ToDateTime(budTemplate.InputDate);
         }
         entities.Bud_TemplateType.FirstOrDefault <Bud_TemplateType>(c => (c.TypeId == budTemplate.BudTempType.Id)).Bud_Template.Add(entity);
         entities.AddToBud_Template(entity);
         entities.SaveChanges();
     }
 }
Esempio n. 5
0
        public static IList <BudTemplate> Select(string tempTypeId)
        {
            IList <BudTemplate> list = new List <BudTemplate>();

            using (pm2Entities entities = new pm2Entities())
            {
                foreach (var typeb in (from temp in entities.Bud_Template
                                       where temp.Bud_TemplateType.TypeId == tempTypeId
                                       orderby temp.InputDate descending
                                       select new { TemplateId = temp.TemplateId, TemplateName = temp.TemplateName, TypeId = temp.Bud_TemplateType.TypeId }).ToList())
                {
                    BudTemplate item = new BudTemplate {
                        Id          = typeb.TemplateId,
                        Name        = typeb.TemplateName,
                        BudTempType = BudTemplateType.GetById(typeb.TypeId)
                    };
                    list.Add(item);
                }
            }
            return(list);
        }
Esempio n. 6
0
        public static IList <BudTemplate> GetByName(string name)
        {
            IList <BudTemplate> list = new List <BudTemplate>();

            using (pm2Entities entities = new pm2Entities())
            {
                foreach (var typea in (from bt in entities.Bud_Template
                                       where bt.TemplateName == name
                                       select new { TemplateId = bt.TemplateId, TemplateCode = bt.TemplateCode, TemplateName = bt.TemplateName, InputUser = bt.InputUser, InputDate = bt.InputDate, TypeId = bt.Bud_TemplateType.TypeId }).ToList())
                {
                    BudTemplate item = new BudTemplate {
                        Id          = typea.TemplateId,
                        Code        = typea.TemplateCode,
                        Name        = typea.TemplateName,
                        InputUser   = typea.InputUser,
                        InputDate   = new DateTime?(typea.InputDate),
                        BudTempType = BudTemplateType.GetById(typea.TypeId)
                    };
                    list.Add(item);
                }
            }
            return(list);
        }
Esempio n. 7
0
        public static BudTemplate GetById(string id)
        {
            BudTemplate template = new BudTemplate();

            using (pm2Entities entities = new pm2Entities())
            {
                var typea = (from bt in entities.Bud_Template
                             where bt.TemplateId == id
                             select new { TemplateId = bt.TemplateId, TemplateCode = bt.TemplateCode, TemplateName = bt.TemplateName, InputUser = bt.InputUser, InputDate = bt.InputDate, TypeId = bt.Bud_TemplateType.TypeId }).FirstOrDefault();
                if (typea != null)
                {
                    template.Id        = id;
                    template.Code      = typea.TemplateCode;
                    template.Name      = typea.TemplateName;
                    template.InputUser = typea.InputUser;
                    template.InputDate = new DateTime?(typea.InputDate);
                    BudTemplateType byId = BudTemplateType.GetById(typea.TypeId);
                    template.BudTempType = byId;
                    return(template);
                }
                return(null);
            }
        }