示例#1
0
        public ActionResult UserDelete(List <int> ids)
        {
            var res = new MgResult();

            //权限先写死
            if (!CurUserInfo.RoleList.Any(i => i.Contains("管理员")))
            {
                res.Code = 999;
                res.Msg  = "您没有权限操作!";
                return(Json(res));
            }
            var result = _unitOfWork.GetRepository <UserInfo>();

            ids.ForEach(i =>
            {
                result.Delete(result.Find(i));
            });
            var r = _unitOfWork.SaveChanges() > 0;

            res.Code = r ? 0 : 1;
            res.Msg  = r ? "ok" : "SaveChanges失败!";
            return(Json(res));
        }
        public IActionResult AddMenu(MenuModel model)
        {
            var res = new MgResult();

            if (!ModelState.IsValid)
            {
                res.Code = 110;
                res.Msg  = "后端模型验证失败!";
                return(Json(res));
            }
            var tempMenu = _mapper.Map <Menu>(model);

            var repoMenu = _unitOfWork.GetRepository <Menu>();

            tempMenu.CreateUser   = CurUserInfo.TrueName;
            tempMenu.CreateUserId = CurUserInfo.UserId;
            tempMenu.CreateTime   = DateTime.Now;
            repoMenu.Insert(tempMenu);
            var r = _unitOfWork.SaveChanges();

            res.Code = r > 0 ? 0 : 1;
            res.Msg  = r > 0 ? "ok" : "SaveChanges失败!";
            return(Json(res));
        }
示例#3
0
        public IActionResult AddColumn(ColumnModel model)
        {
            var res = new MgResult();

            if (!ModelState.IsValid)
            {
                res.Code = 110;
                res.Msg  = "后端模型验证失败!";
                return(Json(res));
            }
            var column = _mapper.Map <Column>(model);

            var repoColumn = _unitOfWork.GetRepository <Column>();

            column.CreateUser   = CurUserInfo.TrueName;
            column.CreateUserId = CurUserInfo.UserId;
            column.CreateTime   = DateTime.Now;
            repoColumn.Insert(column);
            var r = _unitOfWork.SaveChanges();

            res.Code = r > 0 ? 0 : 1;
            res.Msg  = r > 0 ? "ok" : "SaveChanges失败!";
            return(Json(res));
        }
示例#4
0
        public ActionResult HolidayBulid()
        {
            try
            {
                var result = new MgResult();
                //https://blog.csdn.net/xinit1/article/details/72833988
                var holidayRep = _unitOfWork.GetRepository <Holiday>();
                var listH      = new List <Holiday>();
                var curDate    = DateTime.Now;
                var year       = curDate.Year;
                for (DateTime dt = new DateTime(year, 1, 1); dt < new DateTime(year + 1, 1, 1); dt = dt.AddDays(1))
                {
                    var t = dt.ToString("yyyyMMdd");
                    if (holidayRep.GetEntities().Any(i => i.HolidayTime.Value.Year
                                                     == dt.Year && i.HolidayTime.Value.Day == dt.Day &&
                                                     i.HolidayTime.Value.Month == dt.Month))
                    {
                        continue;
                    }

                    var url   = $"http://api.goseek.cn/Tools/holiday?date={t}";
                    var getRs = url.GetPostPage().JsonConvert <ResultHolidy>();
                    if (dt.DayOfWeek.ToString() != "Saturday" && getRs.data != 0)
                    {
                        if (getRs.data == 2)
                        {
                            listH.Add(new Holiday()
                            {
                                Desc        = "节假日",
                                HolidayTime = DateTime.Parse(dt.ToString("yyyy-MM-dd"))
                                ,
                                CreateTime   = DateTime.Now,
                                CreateUser   = CurUserInfo.UserName,
                                CreateUserId = CurUserInfo.UserId
                            });
                        }
                        else
                        {
                            listH.Add(new Holiday()
                            {
                                Desc        = "周日",
                                HolidayTime = DateTime.Parse(dt.ToString("yyyy-MM-dd"))
                                ,
                                CreateTime   = DateTime.Now,
                                CreateUser   = CurUserInfo.UserName,
                                CreateUserId = CurUserInfo.UserId
                            });
                        }
                    }
                }
                if (listH.Count == 0)
                {
                    result.Code = 2;
                    result.Msg  = "没有符合的日期";
                    return(Json(result));
                }
                holidayRep.Insert(listH);
                var r = _unitOfWork.SaveChanges();
                result.SetResult(r);
                return(Json(result));
            }
            catch (Exception e)
            {
                _logger.Error("生成日期报错~", e);
                throw;
            }
        }
示例#5
0
        public IActionResult EditDataManage(DataManageModel model)
        {
            var res = new MgResult();


            var user = _unitOfWork.GetRepository <UserInfo>().
                       GetEntities(x => x.Id == CurUserInfo.UserId).FirstOrDefault();

            if (user?.DepartMentId != 3 || CurUserInfo.RoleList.All(i => i != "经理"))
            {
                res.Code = 999;
                res.Msg  = "只有部门经理可以操作!";
                return(Json(res));
            }
            var receivePerson = _unitOfWork.GetRepository <ReceivePerson>()
                                .GetEntities(i => i.OrderId == model.OrderId && i.UserInfoId == CurUserInfo.UserId).FirstOrDefault();

            if (receivePerson == null)
            {
                res.Code = 1;
                res.Msg  = "您不是该订单的接单人,不允许保存订单资料库!";
                return(Json(res));
            }
            var orderCount = receivePerson.TotalCount;
            var dataMange  = _unitOfWork.GetRepository <DataManage>().GetEntities();
            var curCount   = dataMange.Where(i => i.OrderId == model.OrderId &&
                                             i.CreateUserId == CurUserInfo.UserId &&
                                             i.Id != model.Id)
                             .Sum(i => i.Count);

            if (curCount + model.Count > orderCount)
            {
                res.Code = 2;
                res.Msg  = $"{ model.OrderId}该订单您应完成总数{orderCount},已经完成{curCount},现有数量{ model.Count}已超标!";
                return(Json(res));
            }
            if (!ModelState.IsValid)
            {
                res.Code = 110;
                res.Msg  = "后端验证不通过!";
                return(Json(res));
            }

            var dataManage = _unitOfWork.GetRepository <DataManage>().Find(model.Id);

            if (dataManage == null)
            {
                res.Code = 120;
                res.Msg  = "资料不存在!";
                return(Json(res));
            }

            _mapper.Map(model, dataManage);
            dataManage.UpdateTime   = DateTime.Now;
            dataManage.UpdateUser   = CurUserInfo.TrueName;
            dataManage.UpdateUserId = CurUserInfo.UserId;
            var r = _unitOfWork.SaveChanges();

            res.Code = r > 0 ? 0 : 1;
            res.Msg  = r > 0 ? "ok" : "SaveChanges失败!";
            return(Json(res));
        }
示例#6
0
        public IActionResult EditOrder(OrderModel model)
        {
            var res = new MgResult();

            if (!ModelState.IsValid)
            {
                res.Code = 110;
                res.Msg  = "后端验证不通过!";
                return(Json(res));
            }
            var order = _unitOfWork.GetRepository <Order>().GetEntities().Include(i => i.ReceivePerson)
                        .FirstOrDefault(i => i.Id == model.Id && i.OrderState == 1);

            if (order == null)
            {
                res.Code = 120;
                res.Msg  = "只有未确认的订单才允许修改!";
                return(Json(res));
            }
            if (order.CreateUser != CurUserInfo.TrueName)
            {
                res.Code = 130;
                res.Msg  = "只有该订单的派单人才允许修改!";
                return(Json(res));
            }
            var dicnum = new Dictionary <int, int>();

            foreach (var s in model.StrNumber.Split('|'))
            {
                dicnum.Add(s.Split(',')[0].ToInt(), s.Split(',')[1].ToInt());
            }
            order.Degree        = model.Degree; order.ExpectTime = model.ExpectTime;
            order.UpdateTime    = DateTime.Now;
            order.OrderName     = model.OrderName;
            order.UpdateUser    = CurUserInfo.TrueName;
            order.UpdateUserId  = CurUserInfo.UserId;
            order.OrderDescribe = model.OrderDescribe;

            order.ReceivePerson.Clear();
            var lisRp = new List <ReceivePerson>();

            model.ReceivePersons.ForEach(i =>
            {
                dicnum.TryGetValue(i, out int tempv);
                lisRp.Add(new ReceivePerson()
                {
                    UserInfoId   = i,
                    ReceiveState = 1,
                    CreateTime   = DateTime.Now,
                    OrderId      = model.Id
                    , TotalCount = tempv
                });
            });
            order.ReceivePerson = lisRp;
            order.OrderTypeIds  = string.Join(",", model.OrderTypeIds.ToArray());

            var r = _unitOfWork.SaveChanges();

            res.Code = r > 0 ? 0 : 1;
            res.Msg  = r > 0 ? "ok" : "SaveChanges失败!";
            return(Json(res));
        }