Example #1
0
 public async Task<int> Save(T_Customer_Task model)
 {
     using (db = new KBLDataContext())
     {
         var entity = await (from t in db.CustomerTasks
                             where t.TaskId == model.TaskId
                             select t).FirstOrDefaultAsync();
         if (entity == null)
         {
             entity = await (from t in db.CustomerTasks
                             where t.CId == model.CId
                             orderby t.StartDate descending
                             select t).FirstOrDefaultAsync();
             if (entity != null)
             {
                 model.Describe = entity.Describe;
                 model.Other = entity.Other;
                 model.During = (model.StartDate - entity.StartDate).Value.Days + "";
                 model.Review = (model.StartDate - entity.StartDate).Value.Days + "";
             }
             db.CustomerTasks.Add(model);
         }
         else
         {
             entity.StartDate = model.StartDate;
             entity.Describe = model.Describe;
             entity.Review = model.Review;
             entity.ReviewStatus = model.ReviewStatus;
             entity.During = model.During;
             entity.Other = model.Other;
             db.Entry(entity).State = EntityState.Modified;
         }
         return await db.SaveChangesAsync();
     }
 }
Example #2
0
        /// <summary>
        /// 用户信息修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<int> Save(T_Customer_Role model)
        {
            using (db = new KBLDataContext())
            {
                var entity = from r in db.CustomerRoles
                             where r.Rid == model.Rid
                             select r;
                T_Customer_Role role = await entity.FirstOrDefaultAsync();

                if (role == null)
                {
                    model.CreateDate = Helper.Comm.GetIntFromTime(DateTime.Now);
                    model.UpdateAccountDate = Helper.Comm.GetIntFromTime(DateTime.Now);
                    db.CustomerRoles.Add(model);
                }
                else
                {
                    role.UserName = model.UserName;
                    role.Password = model.Password;
                    role.Cid = model.Cid;
                    role.UpdateAccountDate = Helper.Comm.GetIntFromTime(DateTime.Now);
                    db.Entry(role).State = EntityState.Modified;
                }
                return await db.SaveChangesAsync();
            }
        }
        public async Task<int> Save(T_Customer_Product model)
        {
            using (db = new KBLDataContext())
            {
                var entity = from t in db.CustomerProducts
                             where t.Pid == model.Pid
                             select t;
                T_Customer_Product _prodcut = await entity.FirstOrDefaultAsync();

                if (_prodcut == null)
                {
                    db.CustomerProducts.Add(model);
                }
                else
                {
                    _prodcut.Name = model.Name;
                    _prodcut.Price = model.Price;
                    _prodcut.Quantity = model.Quantity;
                    _prodcut.SaleAmount = model.SaleAmount;
                    _prodcut.Vp = model.Vp;
                    _prodcut.PurchasingDate = model.PurchasingDate;
                    _prodcut.GeneratintVpDate = model.GeneratintVpDate;
                    db.Entry(_prodcut).State = EntityState.Modified;
                }
                return await db.SaveChangesAsync();
            }
        }
Example #4
0
 /// <summary>
 /// 用户列表
 /// </summary>
 /// <returns></returns>
 public async Task<IEnumerable<T_Customer_Role>> List()
 {
     using (db = new KBLDataContext())
     {
         var entities = from r in db.CustomerRoles
                        select r;
         return await entities.ToListAsync();
     }
 }
 public async Task<object> List(long customerId)
 {
     using (db = new KBLDataContext())
     {
         var entities = from t in db.CustomerProducts
                        where t.Cid == customerId
                        select t;
         return await entities.ToListAsync();
     }
 }
 public async Task<object> GetCustomerTracks(int cid)
 {
     using (db = new KBLDataContext())
     {
         var entities = from t in db.CustomerTracks
                      where t.TrackID == cid
                      select t;
         return await entities.ToListAsync();
     }
 }
Example #7
0
 /// <summary>
 /// 用户名检查
 /// </summary>
 /// <param name="userName"></param>
 /// <returns></returns>
 public async Task<T_Customer_Role> Check(string userName)
 {
     using (db = new KBLDataContext())
     {
         var entity = from r in db.CustomerRoles
                      where r.UserName == userName
                      select r;
         return await entity.FirstOrDefaultAsync();
     }
 }
 public async Task<object> GetCustomerTrack(int trackID)
 {
     using (db = new KBLDataContext())
     {
         var entity = from t in db.CustomerTracks
                      where t.TrackID == trackID
                      select t;
         return await entity.FirstOrDefaultAsync();
     }
 }
 public async Task<object> Find(long id)
 {
     using (db = new KBLDataContext())
     {
         var entity = from t in db.CustomerProducts
                        where t.Pid == id
                        select t;
         return await entity.FirstOrDefaultAsync();
     }
 }
Example #10
0
 public async Task<T_Customer_Role> SignIn(string userName,string password)
 {
     using (db = new KBLDataContext())
     {
         var entity = from r in db.CustomerRoles
                      where r.UserName == userName && r.Password == password
                      select r;
         return await entity.FirstOrDefaultAsync();
     }
 }
Example #11
0
 /// <summary>
 /// 精确查找
 /// </summary>
 /// <param name="cid"></param>
 /// <returns></returns>
 public async Task<T_Customer_Role> Find(long cid)
 {
     using (db = new KBLDataContext())
     {
         var entity = from r in db.CustomerRoles
                      where r.Cid == cid
                      select r;
         return await entity.FirstOrDefaultAsync();
     }
 }
Example #12
0
 public async Task<object> Find(long taskId)
 {
     using (db = new KBLDataContext())
     {
         var entity = from t in db.CustomerTasks
                      where t.TaskId == taskId
                      select t;
         return await entity.FirstOrDefaultAsync();
     }
 }
Example #13
0
 public async Task<object> Find(long cid)
 {
     using (db = new KBLDataContext())
     {
         var entity = from c in db.Customers
                      where c.Cid == cid
                      select c;
         return await entity.FirstOrDefaultAsync();
     }
 }
 public async Task<object> Find(long Id)
 {
     using (db = new KBLDataContext())
     {
         var entities = from c in db.CustomerSchedule
                        where c.Id == Id
                        select c;
         var data = await entities.FirstOrDefaultAsync();
         return data;
     }
 }
Example #15
0
 public async Task<List<T_Customer>> CheckCustomerCName(string cname)
 {
     using (db = new KBLDataContext())
     {
         ///获取登录权限
         var customers = await (from c in db.Customers
                               where c.CName.IndexOf(cname) > -1
                               select c).ToListAsync();
         return customers;
     }
 }
 public async Task<object> List(long customerId)
 {
     using (db = new KBLDataContext())
     {
         var entities = from c in db.CustomerSchedule                               
                        where c.CustomerId == customerId
                        select c;
         var data = await entities.ToListAsync();
         return data;
     }
 }
Example #17
0
 public async Task<object> List(long cid)
 {
     using (db = new KBLDataContext())
     {
         var entities = from t in db.CustomerTasks
                        where t.CId == cid
                        orderby t.StartDate ascending
                        select t;
         return await entities.ToListAsync();
     }
 }
Example #18
0
 public async Task<int> Remove(long taskId)
 {
     using (db = new KBLDataContext())
     {
         var entity = await (from t in db.CustomerTasks
                             where t.TaskId == taskId
                             select t).FirstOrDefaultAsync();
         if (entity != null)
         {
             db.CustomerTasks.Remove(entity);
         }
         return await db.SaveChangesAsync();
     }
 }
 public async Task<int> Remove(long Id)
 {
     using (db = new KBLDataContext())
     {
         var entity = from c in db.CustomerSchedule
                      where c.Id == Id
                      select c;
         T_Customer_Schedule _model = await entity.FirstOrDefaultAsync();
         if (_model != null)
         {
             db.CustomerSchedule.Remove(_model);
         }
         return await db.SaveChangesAsync();
     }
 }
 public async Task<int> remove(long id)
 {
     using (db = new KBLDataContext())
     {
         var entity = from t in db.CustomerProducts
                      where t.Pid == id
                      select t;
         T_Customer_Product _prodcut = await entity.FirstOrDefaultAsync();
         if (_prodcut != null)
         {
             db.CustomerProducts.Remove(_prodcut);
             return await db.SaveChangesAsync();
         }
         return 0;
     }
 }
Example #21
0
 public async Task<object> Save(T_Customer model)
 {
     var cname = model.CName;
     var contact = model.Contact;
     using (db = new KBLDataContext())
     {
         var exist = await (from c in db.Customers where c.Cid == model.Cid select c).FirstOrDefaultAsync();
         if (exist == null)
         {
             db.Customers.Add(model);
             int effects = await db.SaveChangesAsync();
             return new
             {
                 effects = effects,
                 model = model
             };
         }
         else
         {
             //UpdateModel();
             exist.Dietitian = model.Dietitian;
             exist.CName = model.CName;
             exist.CustomerNo = model.CustomerNo;
             exist.Age = model.Age;
             exist.CategoryID = model.CategoryID;
             exist.Addr = model.Addr;
             exist.Weight = model.Weight;
             exist.Height = model.Height;
             exist.Gender = model.Gender;
             exist.Contact = model.Contact;
             exist.CardType = model.CardType;
             exist.Married = model.Married;
             exist.Address = model.Address;
             exist.Remark = model.Remark;
             db.Entry(exist).State = EntityState.Modified;
             int effects = await db.SaveChangesAsync();
             return new
             {
                 effects = effects
             };
         }
         
     }
 }
Example #22
0
        public async Task<object> List(CustomerParams param)
        {
            using (db = new KBLDataContext())
            {
                var entities = from c in db.Customers  
                               join t in db.CustomerTasks on c.Cid equals t.CId into ct
                               from lct in ct.DefaultIfEmpty()
                               where (c.CategoryID == param.CategoryId && !string.IsNullOrEmpty(param.CategoryId) || string.IsNullOrEmpty(param.CategoryId))
                               group lct by c into gct
                               select gct;
                var data = await entities.ToListAsync();

                var json = from gct in data
                           orderby gct.Key.Cid descending
                           select new
                           {
                               c = gct.Key,
                               t = new
                               {
                                   Unfinished = gct.Any(a => a != null) ? gct.Where(w => w.StartDate.Value.Date < DateTime.Now.Date && w.ReviewStatus == false).Select(s => new {
                                       s.StartDate,
                                       s.ReviewStatus
                                   }) : new object { },
                                   //Prev = gct!=null ? gct.Any(a=>a !=null)? gct.Where(w => w.StartDate.Value.Date < DateTime.Now.Date).OrderBy(o => o.StartDate).Take(1):null : null,
                                   Prev = gct.Any(a => a != null) ? gct.Where(w => w.StartDate.Value.Date < DateTime.Now.Date).OrderBy(o => o.StartDate).LastOrDefault() : null,
                                   //Next = gct != null ? gct.Any(a => a != null) ? gct.Where(w => w.StartDate.Value.Date > DateTime.Now.Date).OrderByDescending(o => o.StartDate).Take(1) : null : null,
                                   Next = gct.Any(a => a != null) ? gct.Where(w => w.StartDate.Value.Date > DateTime.Now.Date).OrderBy(o => o.StartDate).FirstOrDefault() : null,
                                   //Today = gct != null ? gct.Any(a => a != null) ? gct.Where(w => w.StartDate.Value.Date == DateTime.Now.Date).OrderByDescending(o => o.StartDate).Take(1) : null : null
                                   Today = gct.Any(a => a != null) ? gct.Where(w => w.StartDate.Value.Date == DateTime.Now.Date).OrderByDescending(o => o.StartDate).LastOrDefault() : null,

                                   Finishing = gct.Any(a => a != null) ? gct.Where(w => w.StartDate.Value.Date > DateTime.Now.Date && w.ReviewStatus == false).Select(s=>new {
                                       s.StartDate,
                                       s.ReviewStatus
                                   }) : new object{ },

                               }
                           };

                return json;
            }
        }
Example #23
0
 /// <summary>
 /// 用户删除
 /// </summary>
 /// <param name="cid"></param>
 /// <returns></returns>
 public async Task<int> remove(long cid)
 {
     using (db = new KBLDataContext())
     {
         var entity = from r in db.CustomerRoles
                      where r.Cid == cid
                      select r;
         T_Customer_Role _prodcut = await entity.FirstOrDefaultAsync();
         if (_prodcut != null)
         {
             db.CustomerRoles.Remove(_prodcut);
             return await db.SaveChangesAsync();
         }
         return 0;
     }
 }