Пример #1
0
        public ActionResult Registers(ServiceCompany serverCompany)
        {
            try
            {
                if (CurrentUser.ServiceCompany == null || CurrentUser.ServiceCompany.State == CompanyState.Locked)
                {
                    HttpFileCollectionBase uploadFile = Request.Files;
                    List <Picture>         pInfo      = new List <Picture>();
                    if (uploadFile.Count > 0)
                    {
                        for (int i = 0; i < uploadFile.Count; i++)
                        {
                            HttpPostedFileBase file = uploadFile[i];
                            string             path = ConfigurationManager.AppSettings["repairImgPath"].ToString() + "/" + PhotoType.Server.ToString() + "/";

                            if (!Directory.Exists(path))
                            {
                                Directory.CreateDirectory(path);
                            }
                            string fileName = Guid.NewGuid().ToString("N") + "." + file.ContentType.ToString().Split('/')[1];
                            file.SaveAs(path + "/" + fileName);

                            pInfo.Add(new Picture
                            {
                                Type       = PhotoType.Server,
                                Url        = PhotoType.Server.ToString() + "/" + fileName,
                                CreateTime = DateTime.Now
                            });
                        }
                    }
                    cService.AddServiceCompanyInfo(serverCompany, CurrentUser.User);
                    CurrentUser.User = new MbContext().User.FirstOrDefault(t => t.Account == CurrentUser.User.Phone);

                    //上传图片
                    if (pInfo.Count != 0)
                    {
                        using (var db = new LZY.BX.Service.Mb.MbContext())
                        {
                            foreach (Picture item in pInfo)
                            {
                                item.OuterId    = CurrentUser.User.ServiceCompanyId;
                                item.CreateTime = DateTime.Now;
                                db.Picture.Add(item);
                            }
                            db.SaveChanges();
                        }
                    }
                    AuthMng.Instance.ResetUserCookie(HttpContext, new UserCookie(
                                                         new AuthUser
                    {
                        User           = CurrentUser.User,
                        UseCompany     = CurrentUser.UseCompany,
                        ServiceCompany = cService.GetServiceInfo(CurrentUser.User)
                    }));
                    return(ResultSuccess("提交成功.请稍后留意审核状态", Url.Action("Order", "Order")));
                }
                else
                {
                    return(ResultError("重复申请,您有一个单位等待审核中."));
                }
            }
            catch (DataExistException ex)
            {
                return(ResultError(ex.Message));
            }
        }
Пример #2
0
        public ActionResult OrderWrite(MainOrder mainOrder)
        {
            try
            {
                HttpFileCollectionBase uploadFile = Request.Files;
                List <Picture>         pInfo      = new List <Picture>();
                if (uploadFile.Count > 0)
                {
                    for (int i = 0; i < uploadFile.Count; i++)
                    {
                        HttpPostedFileBase file = uploadFile[i];
                        string             path = ConfigurationManager.AppSettings["repairImgPath"].ToString() + "/" + PhotoType.Device.ToString() + "/";

                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }
                        string fileName = Guid.NewGuid().ToString("N") + "." + file.ContentType.ToString().Split('/')[1];
                        file.SaveAs(path + "/" + fileName);

                        pInfo.Add(new Picture
                        {
                            Type       = PhotoType.Device,
                            Url        = PhotoType.Device.ToString() + "/" + fileName,
                            CreateTime = DateTime.Now
                        });
                    }
                }
                mainOrder.ServiceCompanyId = CurrentUser.User.ServiceCompanyId;
                long deviceId = new DeviceService().DeviceWrite(mainOrder);
                if (deviceId > 0)
                {
                    //上传图片
                    if (pInfo.Count != 0)
                    {
                        using (var db = new LZY.BX.Service.Mb.MbContext())
                        {
                            foreach (Picture item in pInfo)
                            {
                                item.OuterId    = deviceId.ToString();
                                item.CreateTime = DateTime.Now;
                                db.Picture.Add(item);
                            }
                            db.SaveChanges();
                        }
                    }
                    //创建新工单
                    mainOrder.MainOrderId      = SequNo.NewId;
                    mainOrder.ServiceCompanyId = CurrentUser.User.ServiceCompanyId;
                    mainOrder.DeviceId         = deviceId;
                    if (new OrderService().Create(mainOrder, CurrentUser.User.ServiceCompany))
                    {
                        return(ResultSuccess("工单已经录入成功", Url.Action("Order", "Order")));
                    }
                    else
                    {
                        return(ResultSuccess("工单录入失败", Url.Action("Order", "OrderWrite")));
                    }
                }
                else
                {
                    return(ResultSuccess("工单录入失败", Url.Action("Order", "OrderWrite")));
                }
            }
            catch (DataExistException ex)
            {
                return(ResultError(ex.Message));
            }
        }