Beispiel #1
0
        public ActionResult SendOrder(long repairOrderId = 0, long serviceCompanyUserId = 0)
        {
            var user   = CurrentUser;
            var result = -1;

            using (var db = new MbContext())
            {
                var repairOrder = db.RepairOrder.FirstOrDefault(x => x.RepairOrderId == repairOrderId);
                #region 写入日志
                var serviceUser = db.User.FirstOrDefault(x => x.UserId == serviceCompanyUserId);
                var log         = new RepairOrderLog()
                {
                    UserId        = serviceCompanyUserId,
                    RepairOrderId = repairOrderId,
                    UserType      = UserType.SvcCompanyUser.ToString(),
                    Content       = string.Format("管理员派单"),
                    CreateTime    = DateTime.Now
                };
                db.RepairOrderLog.AddOrUpdate(log);
                db.SaveChanges();
                #endregion

                //指派维修工
                if (repairOrder != null)
                {
                    repairOrder.State = RepairState.Sended.ToString();
                    repairOrder.LastStateUpdateTime = DateTime.Now;
                    db.RepairOrder.AddOrUpdate(repairOrder);
                    db.SaveChanges();
                }
                var serviceOrder = db.ServiceCompanyRepairOrder.FirstOrDefault(x => x.RepairOrderId == repairOrderId);
                if (serviceOrder != null)
                {
                    serviceOrder.State               = RepairState.Sended.ToString();
                    serviceOrder.UserId              = serviceCompanyUserId;
                    serviceOrder.Phone               = serviceUser.Phone;
                    serviceOrder.Contact             = serviceUser.RealName;
                    serviceOrder.LastStateUpdateTime = DateTime.Now;
                    db.ServiceCompanyRepairOrder.AddOrUpdate(serviceOrder);
                    result = db.SaveChanges();
                }
                var useCompanyOrder = db.UseCompanyRepairOrder.FirstOrDefault(x => x.RepairOrderId == repairOrderId);
                if (useCompanyOrder != null)
                {
                    useCompanyOrder.State = RepairState.Sended.ToString();
                    useCompanyOrder.LastStateUpdateTime = DateTime.Now;
                    db.UseCompanyRepairOrder.AddOrUpdate(useCompanyOrder);
                    db.SaveChanges();
                }
                var content = "管理员派单";
                RepairSvr.Instance.CreateMassage(repairOrderId, content, serviceUser.UserId, serviceUser.RealName, serviceCompanyUserId, serviceUser.RealName, false);
            }

            if (result > 0)
            {
                return(Content("<script>alert('操作成功');window.location.href='/RepairOrder/Index'</script>"));
            }
            return(Content("<script>alert('操作失败');window.location.href='/RepairOrder/Index'</script>"));
        }
        /// <summary>
        /// 用户解除绑定
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult UnBindUser(string id)
        {
            //TODO 获取当前登录用户的报修单位ID
            var dlgInf = new DlgConfirmInfo();

            using (var db = new MbContext())
            {
                var model = db.UseCompanyUser.FirstOrDefault(x => x.UserId == id && x.UseCompanyId == CurrentUser.User.UseCompanyId);
                if (model != null)
                {
                    //获取用户信息,更新单位信息
                    var user = db.User.FirstOrDefault(x => x.UserId == id);
                    user.UseCompanyId     = null;
                    user.UseCompanyUserId = null;

                    db.UseCompanyUser.Remove(model);
                }
                if (db.SaveChanges() > 0)
                {
                    dlgInf.Title   = "成功";
                    dlgInf.Content = "解除绑定成功";
                    dlgInf.Type    = InfoType.Success;

                    return(View("dlg_confirm_info", dlgInf));
                }
                dlgInf.Title   = "失败";
                dlgInf.Content = "解除绑定失败";
                dlgInf.Type    = InfoType.Error;
                return(View("dlg_confirm_info", dlgInf));
            }
        }
 public ActionResult ManufacturerEdit(Manufacturer model)
 {
     using (var db = new MbContext())
     {
         if (!(model.ManufacturerId > 0))
         {
             model.ManufacturerId = SequNo.NewId;
             model.CreateTime     = DateTime.Now;
         }
         else
         {
             var manufacturer = db.Manufacturer.FirstOrDefault(x => x.ManufacturerId == model.ManufacturerId);
             if (manufacturer != null)
             {
                 model.CreateTime = manufacturer.CreateTime;
                 model.Longitude  = manufacturer.Longitude;
                 model.Dimension  = manufacturer.Dimension;
                 model.Note       = manufacturer.Note;
             }
         }
         db.Manufacturer.AddOrUpdate(model);
         if (db.SaveChanges() > 0)
         {
             return(Content("<script>alert('操作成功');window.location.href='/SysAdmin/CommData/ManufacturerSys'</script>"));
         }
         return(Content("<script>alert('操作失败');window.location.href='/SysAdmin/CommData/ManufacturerSys'</script>"));
     }
 }
 public ActionResult BrandEdit(Brand model)
 {
     using (var db = new MbContext())
     {
         if (model.BrandId <= 0)
         {
             model.BrandId    = SequNo.NewId;
             model.CreateTime = DateTime.Now;
         }
         else
         {
             var brand = db.Brand.FirstOrDefault(x => x.BrandId == model.BrandId);
             if (brand != null)
             {
                 model.Note       = brand.Note;
                 model.CreateTime = brand.CreateTime;
             }
         }
         db.Brand.AddOrUpdate(model);
         if (db.SaveChanges() > 0)
         {
             return(Content("<script>alert('操作成功');window.location.href='/SysAdmin/CommData/BrandSys'</script>"));
         }
         return(Content("<script>alert('操作失败');window.location.href='/SysAdmin/CommData/BrandSys'</script>"));
     }
 }
 public ActionResult ProductEdit(Product models)
 {
     using (var db = new MbContext())
     {
         if (models.ProductId <= 0)
         {
             models.ProductId  = SequNo.NewId;
             models.CreateTime = DateTime.Now;
         }
         else
         {
             var product = db.Product.FirstOrDefault(x => x.ProductId == models.ProductId);
             if (product != null)
             {
                 models.Note       = product.Note;
                 models.BirthTime  = product.BirthTime;
                 models.CreateTime = product.CreateTime;
             }
         }
         db.Product.AddOrUpdate(models);
         if (db.SaveChanges() > 0)
         {
             return(Content("<script>alert('操作成功');window.location.href='/SysAdmin/CommData/ProductSys'</script>"));
         }
         return(Content("<script>alert('操作失败');window.location.href='/SysAdmin/CommData/ProductSys'</script>"));
     }
 }
Beispiel #6
0
 public virtual int Save(BreakRuleAnnal model)
 {
     using (var db = new MbContext())
     {
         db.BreakRuleAnnal.Add(model);
         return(db.SaveChanges());
     }
 }
Beispiel #7
0
        /// <summary>
        /// 绑定用户
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public ActionResult BindUser(string userId)
        {
            var dlgInf = new DlgConfirmInfo();

            //TODO 获取当前登录用户的报修单位ID
            using (var db = new MbContext())
            {
                //DOTO是否存在报修单位
                var useCompanyUser =
                    db.UseCompanyUser
                    .FirstOrDefault(x => x.UserId == userId);

                //DOTO是否存在服务单位
                var serviceCompanyUser =
                    db.ServiceCompanyUser
                    .FirstOrDefault(x => x.UserId == userId);

                if (serviceCompanyUser != null)
                {
                    dlgInf.Title   = "失败";
                    dlgInf.Content = "该用户已被绑定";
                    dlgInf.Type    = InfoType.Error;
                    return(View("dlg_confirm_info", dlgInf));
                }

                if (useCompanyUser != null)
                {
                    dlgInf.Title   = "失败";
                    dlgInf.Content = "该用户已绑定其他单位";
                    dlgInf.Type    = InfoType.Error;
                    return(View("dlg_confirm_info", dlgInf));
                }
                string ServiceCompanyUserId = SequNo.NewId;
                db.ServiceCompanyUser.Add(new ServiceCompanyUser()
                {
                    ServiceCompanyUserId = ServiceCompanyUserId,
                    ServiceCompanyId     = CurrentUser.User.ServiceCompanyId,
                    UserId     = userId,
                    CreateTime = DateTime.Now,
                });
                //获取用户信息,更新单位信息
                var user = db.User.FirstOrDefault(x => x.UserId == userId);
                user.ServiceCompanyId     = CurrentUser.User.ServiceCompanyId;
                user.ServiceCompanyUserId = ServiceCompanyUserId;
                if (db.SaveChanges() > 0)
                {
                    dlgInf.Title   = "成功";
                    dlgInf.Content = "绑定成功";
                    dlgInf.Type    = InfoType.Success;

                    return(View("dlg_confirm_info", dlgInf));
                }
                dlgInf.Title   = "失败";
                dlgInf.Content = "绑定失败";
                dlgInf.Type    = InfoType.Error;
                return(View("dlg_confirm_info", dlgInf));
            }
        }
Beispiel #8
0
        public ActionResult AddOrEdit(Device dev)
        {
            using (var db = new MbContext())
            {
                db.Device.AddOrUpdate(dev);

                return(db.SaveChanges() > 0 ? ResultSuccess("操作成功!") : ResultError("操作异常!"));
            }
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="pCategory">父节点</param>
        /// <param name="category"></param>
        /// <returns></returns>
        public static bool Insert(Category category)
        {
            //var newList = ToList();

            //var model = newList.Find(t => t.CategoryId == category.Pid);

            //if (model == null)
            //{
            //    return false;
            //}

            //using (var db = new MbContext())
            //{
            //    category.CategoryId = SequNo.NewId;
            //    category.CreateTime = DateTime.Now;

            //    db.Category.Add(category);

            //    if (db.SaveChanges() > 0)
            //    {
            //        //指定父节点
            //        category.ParentItem = model;
            //        //添加子节点
            //        model.SubItems.Add(category);
            //        //排序
            //        model.SubItems.Sort((x, y) => x.SortField.CompareTo((y.SortField)));

            //        return true;
            //    }

            //    return false;
            //}

            using (var db = new MbContext())
            {
                //var model = db.Category.FirstOrDefault(t => t.CategoryId == category.Pid);
                //if (model == null)
                //{
                //    //DOTO 没有存在父节点,不允许添加
                //    return false;
                //}

                category.CategoryId = SequNo.NewId;
                category.CreateTime = DateTime.Now;

                db.Category.Add(category);

                if (db.SaveChanges() > 0)
                {
                    //DOTO 删除缓存
                    HttpRuntime.Cache.Remove(_categoryTreeCacheKey);
                    return(true);
                }

                return(false);
            }
        }
Beispiel #10
0
        public ActionResult ServerPassedAudit(long id, string reason)
        {
            using (var db = new MbContext())
            {
                ServiceCompany model = db.ServiceCompany.FirstOrDefault(t => t.ServiceCompanyId == id && t.State == CompanyState.NotActive);

                if (model == null)
                {
                    return(ResultError("审核异常."));
                }


                //reason为空,则审核通过
                if (string.IsNullOrEmpty(reason))
                {
                    model.State = CompanyState.Normal;
                }
                else
                {
                    model.State = CompanyState.Locked;
                    model.Note  = reason;
                }

                db.ServiceCompany.AddOrUpdate(model);

                if (model.State == CompanyState.Normal)
                {
                    //更新用户的UserId的RoleKey,以及
                    var  cId      = SequNo.NewId;
                    User UserInfo = db.User.FirstOrDefault(x => x.ServiceCompanyId == model.ServiceCompanyId);
                    UserInfo.RoleKey = UserInfo.RoleKey | UserType.SvcCompanyUserAdmin;
                    UserInfo.ServiceCompanyUserId = cId;
                    UserInfo.UserState            = UserState.Normal;
                    db.User.AddOrUpdate(UserInfo);
                    //db.ServiceCompanyUser.Add(new ServiceCompanyUser
                    //{
                    //    ServiceCompanyUserId = cId,
                    //    UserId = UserInfo.UserId,
                    //    ServiceCompanyId = model.ServiceCompanyId,
                    //    Title = string.Empty,
                    //    State = UserState.Normal,
                    //    CreateTime = DateTime.Now
                    //});
                }

                if ((model.State == CompanyState.Normal && db.SaveChanges() == 2) || (model.State == CompanyState.Locked && db.SaveChanges() == 1))
                {
                    return(ResultSuccess("操作成功."));
                }
                else
                {
                    return(ResultError("操作失败."));
                }
            }
        }
Beispiel #11
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public virtual int Update(WaveAnnal item)
        {
            var result = -1;

            using (var db = new MbContext())
            {
                db.WaveAnnal.AddOrUpdate(item);
                result = db.SaveChanges();
            }
            return(result);
        }
Beispiel #12
0
        /// <summary>
        /// 增加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public virtual int Save(Equipment model)
        {
            var result = -1;

            using (var db = new MbContext())
            {
                db.Equipment.Add(model);
                result = db.SaveChanges();
            }
            return(result);
        }
Beispiel #13
0
        /// <summary>
        /// 增加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public virtual int Save(CardAnnal model)
        {
            var result = -1;

            using (var db = new MbContext())
            {
                db.CardAnnal.Add(model);
                result = db.SaveChanges();
            }
            return(result);
        }
        public void UpdateCategoryTest()
        {
            var arr = new long[] { 1918, 1917 };

            using (var mb = new MbContext())
            {
                var list = mb.Device.Where(t => arr.Contains(t.DeviceId)).ToList();
                list.ForEach(item => item.CategoryId = 1);
                mb.SaveChanges();
            }
        }
Beispiel #15
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="category"></param>
        /// <returns></returns>
        public static bool Update(Category category)
        {
            //var newList = ToList();

            //var model = newList.Find(t => t.CategoryId == category.CategoryId);
            //if (model == null)
            //{
            //    return false;
            //}

            //using (var db = new MbContext())
            //{
            //    //DOTO 数据库操作
            //    var dCategory = db.Category.FirstOrDefault(t => t.CategoryId == category.CategoryId);

            //    dCategory.Name = category.Name;
            //    dCategory.SortField = category.SortField;

            //    if (db.SaveChanges() > 0)
            //    {
            //        //DOTO 修改
            //        model.Name = category.Name;
            //        model.SortField = category.SortField;

            //        if (model.ParentItem != null)
            //        {
            //            model.ParentItem.SubItems.Sort((x, y) => x.SortField.CompareTo((y.SortField)));
            //        }
            //        return true;
            //    }
            //    return false;
            //}

            using (var db = new MbContext())
            {
                //DOTO 数据库操作
                var dCategory = db.Category.FirstOrDefault(t => t.CategoryId == category.CategoryId);
                if (dCategory == null)
                {
                    //DOTO 找不到对应的节点
                    return(false);
                }
                dCategory.Name      = category.Name;
                dCategory.SortField = category.SortField;

                if (db.SaveChanges() > 0)
                {
                    //DOTO 删除缓存
                    HttpRuntime.Cache.Remove(_categoryTreeCacheKey);
                    return(true);
                }
                return(false);
            }
        }
Beispiel #16
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public virtual int Update(AreaAndEqu item)
        {
            var result = -1;

            using (var db = new MbContext())
            {
                db.AreaAndEqu.AddOrUpdate(item);
                result = db.SaveChanges();
            }
            return(result);
        }
Beispiel #17
0
        /// <summary>
        /// 增加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public virtual int Save(AreaAndEqu model)
        {
            var result = -1;

            using (var db = new MbContext())
            {
                db.AreaAndEqu.Add(model);
                result = db.SaveChanges();
            }

            return(result);
        }
Beispiel #18
0
        //超过48小时的自动确认
        private static void AutoWorkedTask()
        {
            ILog log = LogManager.GetLogger("AutoWorkedTask");

            try
            {
                using (var mb = new MbContext())
                {
                    using (TransactionScope scope = new TransactionScope())
                    {
                        //获取订单数量
                        var workedList = mb.Database.SqlQuery <MainOrder>(@"SELECT mo.* from mainorder  mo
                            left join orderlog  ol
                            on mo.MainOrderId=ol.MainOrderId and mo.State=ol.State
                            where mo.State=64 and datediff(NOW(),ol.CreateTime)>=2;").ToList();

                        if (workedList.Count > 0)
                        {
                            //超时的订单编号
                            var mainOrderIdArr = "(\"" + String.Join("\",\"", workedList.Select(m => m.MainOrderId).ToArray()) + "\")";
                            //要更新的数据
                            mb.Database.ExecuteSqlCommand(string.Format(@"update mainorder  set State=1024 where MainOrderId in {0}", mainOrderIdArr));
                            //往OrderLog里面更新数据
                            List <OrderLog> infos = new List <OrderLog>();
                            foreach (var item in workedList)
                            {
                                infos.Add(new OrderLog
                                {
                                    MainOrderId = item.MainOrderId,
                                    UserId      = item.UserId,
                                    State       = OrderState.Confirm,
                                    Content     = "[用户]已确认工单,完成",
                                    CreateTime  = DateTime.Now
                                });
                            }
                            mb.OrderLog.AddRange(infos);
                            mb.SaveChanges();
                            scope.Complete();
                            log.Info("AutoWorkedTask:--" + DateTime.Now + "--已经更新未确认的订单数量:" + workedList.Count.ToString() + "条");
                        }
                        else
                        {
                            log.Info("AutoWorkedTask:--" + DateTime.Now + "--没有超过48小时的订单");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Info("AutoWorkedTask:--" + DateTime.Now + "--" + ex.Message);
            }
        }
Beispiel #19
0
        //messageTip 超过48小时短信提示
        private static void SendWoekingOverTimeInfo()
        {
            ILog log = LogManager.GetLogger("SendWoekingOverTimeInfo");

            try
            {
                if (DateTime.Now.Hour >= 7 && DateTime.Now.Hour <= 21)
                {
                    using (var mb = new MbContext())
                    {
                        using (TransactionScope scope = new TransactionScope())
                        {
                            //获取订单数量
                            var workArr      = mb.Database.SqlQuery <MainOrder>(@"SELECT mo.* from mainorder  mo
                            left join orderlog  ol on mo.MainOrderId = ol.MainOrderId and mo.State = ol.State  
                            where(mo.State = 16 or mo.State = 32) and mo.SMSNotification=0 and datediff(NOW(), ol.CreateTime) >= 2;").ToList();
                            var userIdArr    = workArr.Select(t => t.ServiceUserId).ToArray();
                            var userPhoneArr = mb.User.Where(t => userIdArr.Contains(t.UserId)).GroupBy(t => t.Phone).Select(t => t.Key).ToArray();
                            if (workArr.Count > 0)
                            {
                                //发短信
                                new Task(new Action(() =>
                                {
                                    foreach (var item in userPhoneArr)
                                    {
                                        SMSManager.Instance.WorkingNotify(item, "维修人员");
                                    }
                                })).Start();
                                //发送之后更新SMSNotification
                                var mainOrderIdArr = "(\"" + String.Join("\",\"", workArr.Select(t => t.MainOrderId).ToArray()) + "\")";
                                mb.Database.ExecuteSqlCommand(string.Format(@"update mainorder  set SMSNotification=1 where MainOrderId in {0}", mainOrderIdArr));
                                mb.SaveChanges();
                                scope.Complete();
                                log.Info("SendWoekingOverTimeInfo:" + DateTime.Now + "---更新了" + workArr.Count.ToString() + "条提示信息工单");
                            }
                            else
                            {
                                log.Info("SendWoekingOverTimeInfo:" + DateTime.Now + "---更新了0条提示信息工单");
                            }
                        }
                    }
                }
                else
                {
                    log.Info("SendWoekingOverTimeInfo:维修人员已经休息,不发送短信提示");
                }
            }
            catch (Exception ex)
            {
                log.Info("SendWoekingOverTimeInfo:" + DateTime.Now + "---" + ex.Message);
            }
        }
Beispiel #20
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Remove(string id)
        {
            using (var db = new MbContext())
            {
                var devId = Convert.ToInt64(id);

                var dev = db.Device.FirstOrDefault(t => t.DeviceId == devId);

                db.Device.Remove(dev);

                return(db.SaveChanges() > 0 ? ResultSuccess("删除成功!") : ResultError("删除异常!"));
            }
        }
        public ActionResult UploadBase64Image(PhotoType Type, string strImage)
        {
            //Logger.InfoFormat("UploadBase64Image:strImage{0}====Type{1}", strImage, Type);
            strImage = strImage.Replace(' ', '+').Substring(strImage.IndexOf(',') + 1);
            strImage = strImage.Trim('\0');
            byte[] arr = Convert.FromBase64String(strImage);
            using (MemoryStream ms = new MemoryStream(arr))
            {
                string path = ConfigurationManager.AppSettings["repairImgPath"].ToString() + "/" + Type.ToString() + "/";

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                string imgName = Guid.NewGuid().ToString("N") + ".jpeg";
                Bitmap bmp     = new Bitmap(ms);
                bmp.Save(path + imgName);
                List <Picture> pInfo = new List <Picture>();

                pInfo.Add(new Picture
                {
                    Type       = Type,
                    Url        = Type.ToString() + "/" + imgName,
                    CreateTime = DateTime.Now,
                    Note       = imgName
                });

                if (pInfo.Count != 0)
                {
                    using (var db = new MbContext())
                    {
                        int i = 0;
                        foreach (Picture item in pInfo)
                        {
                            item.CreateTime = DateTime.Now;
                            item.SortField  = i;
                            i++;
                            db.Picture.Add(item);
                            db.SaveChanges();
                        }
                    }
                    return(Json(pInfo.Select(x => new { PictureId = x.PictureId, Name = x.Note }).ToArray()));
                }
                else
                {
                    return(Json(new { error = "图片数量不能0" }));
                }
            }
        }
Beispiel #22
0
        public virtual int Delete(long id)
        {
            var result = -1;

            using (var db = new MbContext())
            {
                var model = db.Freshen.FirstOrDefault(x => x.FreshenId == id);
                if (model != null)
                {
                    db.Freshen.Remove(model);
                    result = db.SaveChanges();
                }
            }
            return(result);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Remove(long id)
        {
            using (var db = new MbContext())
            {
                var dev    = db.Device.FirstOrDefault(t => t.DeviceId == id);
                var devcon = db.DeviceContract.FirstOrDefault(t => t.DeviceId == id);
                if (devcon != null)
                {
                    db.DeviceContract.Remove(devcon);
                }
                db.Device.Remove(dev);

                return(db.SaveChanges() > 0 ? ResultSuccess("删除成功!") : ResultError("删除异常!"));
            }
        }
 public ActionResult UserDelete(long id)
 {
     using (var db = new MbContext())
     {
         var model = db.User.FirstOrDefault(x => x.UserId == id);
         if (model != null)
         {
             db.User.Remove(model);
         }
         if (db.SaveChanges() > 0)
         {
             return(Content("<script>alert('操作成功');window.location.href='/SysAdmin/Author/User'</script>"));
         }
         return(Content("<script>alert('操作失败');window.location.href='/SysAdmin/Author/User'</script>"));
     }
 }
 public ActionResult ProductDelete(long id)
 {
     using (var db = new MbContext())
     {
         var model = db.Product.FirstOrDefault(x => x.ProductId == id);
         if (model != null)
         {
             db.Product.Remove(model);
         }
         if (db.SaveChanges() > 0)
         {
             return(Content("<script>alert('操作成功');window.location.href='/SysAdmin/CommData/ProductSys'</script>"));
         }
         return(Content("<script>alert('操作失败');window.location.href='/SysAdmin/CommData/ProductSys'</script>"));
     }
 }
Beispiel #26
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public virtual int Delete(long id)
        {
            var result = -1;

            using (var db = new MbContext())
            {
                var brands = db.WaveAnnal.FirstOrDefault(x => x.WaveAnnalId == id);

                if (brands != null)
                {
                    db.WaveAnnal.Remove(brands);
                    result = db.SaveChanges();
                }
            }
            return(result);
        }
Beispiel #27
0
        public virtual int Save(string waveCardId)
        {
            var result = -1;

            using (var db = new MbContext())
            {
                var model = new WaveAnnal()
                {
                    WaveCardId = waveCardId,
                    CreateTime = DateTime.Now
                };
                db.WaveAnnal.Add(model);
                result = db.SaveChanges();
            }

            return(result);
        }
 public ActionResult ChangePassword(User model)
 {
     using (var db = new MbContext())
     {
         var oldPassword = Request["OldPassword"];
         var newPassword = Request["password"];
         var safty       = db.SafetyAccount.FirstOrDefault(x => x.UserId == model.UserId);
         if (safty.Content != oldPassword)
         {
             return(View());
         }
         safty.Content = Md5Helper.MD5Encrption(newPassword);
         db.SafetyAccount.AddOrUpdate(safty);
         db.SaveChanges();
         return(Redirect("/Login/Index"));
     }
 }
Beispiel #29
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static bool Remove(long id)
        {
            //var newList = ToList();

            //var category = newList.Find(t => t.CategoryId == id);
            //if (category == null)
            //{
            //    return false;
            //}
            //var pCategory = newList.Find(t => t.CategoryId == category.Pid);
            //if (pCategory == null)
            //{
            //    return false;
            //}

            //using (var db = new MbContext())
            //{
            //    //DOTO 数据库删除
            //    var dCategory = db.Category.FirstOrDefault(t => t.CategoryId == id);
            //    db.Category.Remove(dCategory);

            //    if (db.SaveChanges() > 0)
            //    {
            //        //DOTO 删除
            //        pCategory.SubItems.Remove(category);
            //        return true;
            //    }
            //    return false;
            //}

            using (var db = new MbContext())
            {
                //DOTO 数据库删除
                var dCategory = db.Category.FirstOrDefault(t => t.CategoryId == id);
                db.Category.Remove(dCategory);

                if (db.SaveChanges() > 0)
                {
                    //DOTO 删除缓存
                    HttpRuntime.Cache.Remove(_categoryTreeCacheKey);
                    return(true);
                }
                return(false);
            }
        }
        /// <summary>
        /// 批量生成二维码并下载
        /// </summary>
        /// <returns></returns>
        public ActionResult CreateQRCodeAndDownload(int number, string info)
        {
            var useCompanyId = Convert.ToInt64(info.Split(',')[0]);
            var code         = Convert.ToString(info.Split(',')[1]);

            var byteList     = new List <byte[]>();
            var fileNameList = new List <string>();
            var codeList     = new List <string>();
            var logoImg      = Image.FromFile(Server.MapPath("/") + "logo/zdLogo.png");
            var fontImg      = Image.FromFile(Server.MapPath("/") + "logo/font.png");
            var count        = 0L;

            using (var db = new MbContext())
            {
                var qrCodeCount = db.QrCodeCount.FirstOrDefault(x => x.CompanyId == useCompanyId);
                if (qrCodeCount == null)
                {
                    qrCodeCount                = new QrCodeCount();
                    qrCodeCount.Count          = 0;
                    qrCodeCount.CompanyId      = useCompanyId;
                    qrCodeCount.LastUpdateTime = DateTime.Now;
                    db.QrCodeCount.Add(qrCodeCount);
                }
                qrCodeCount.Count         += number;
                qrCodeCount.LastUpdateTime = DateTime.Now;
                count = qrCodeCount.Count;

                db.SaveChanges();
            }

            for (var i = 0; i < number; i++)
            {
                var cd = string.Format("{0}{1}", code, (count - number + i + 1).ToString().PadLeft(6, '0'));

                fileNameList.Add(cd);
                byteList.Add(QRCodeHelper.GetCode(cd, logoImg, fontImg));

                codeList.Add(cd);
            }
            EquipmentSvr.Instance.CreateQRCode(codeList, useCompanyId);
            DownZip(byteList, fileNameList, "NewQRCode");
            return(RedirectToAction("Index"));
        }