public ActionResult Edit(string RoleId, string Compcd)
        {
            try
            {
                var con = new Conditions <DataBase.TSYSROL>();

                con.And(x => x.Comp_Cd == Compcd &&
                        x.Role_Id == RoleId);

                RoleAuth roleAuth = _tsysrolRepo.Get(con);

                if (roleAuth == null)
                {
                    throw new NullReferenceException($"no find data");
                }

                return(View("Edit", new RoleAuthViewModel(roleAuth, new List <AuthData>())
                {
                    WorkType = AuthNodeType.Edit
                }));
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
            }
            return(View());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 取得技師證件照
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public ActionResult GetTechnician(string filePath)
        {
            try
            {
                var url = ServerProfile.GetInstance().TECHNICIAN_PATH;

                var fullPath = url + filePath;

                if (!System.IO.File.Exists(fullPath))
                {
                    fullPath = ServerProfile.GetInstance().NON_FILE_PATH;
                }

                if (string.IsNullOrEmpty(fullPath))
                {
                    throw new NullReferenceException($"no find data");
                }

                return(File(fullPath, fullPath.GetContentType()));
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
        }
        public ActionResult Search(string UserID, string Compcd)
        {
            try
            {
                #region Get UserBase
                var con = new Conditions <DataBase.TUSRMST>();
                //con.Include(x => x.TSYSROL);
                con.Include(x => x.TUSRDTL);
                con.And(x => x.Comp_Cd == Compcd &&
                        x.User_Id == UserID);
                UserBase user = _tusrmstRepo.Get(con);
                if (user == null)
                {
                    throw new NullReferenceException($"no find data");
                }
                #endregion

                #region GetRoleList
                var rolecon = new Conditions <DataBase.TSYSROL>();
                rolecon.And(x => !string.IsNullOrEmpty(x.Comp_Cd)); // 排除空白
                var rolelist = _tsysrolRepo.GetList(rolecon);
                #endregion



                return(View("Edit", new MemberSetViewModel(user.RoleAuth ?? new RoleAuth()
                {
                    PageAuth = user.PageAuth
                })
                {
                    AuthNodeType = AuthNodeType.Read,  //模式
                    RoleId = user.RoleId,              //權限編號
                    Compcd = user.CompCd,              //公司編號
                    UserID = user.UserId,              //帳號
                    UserName = user.UserId,            //帳號
                    PasswordHash = user.Password,      //密碼
                    CorpUserName = user.UserName,      //姓名
                    PhoneNumber = user.MobileTel,      //電話
                    Email = user.Email,                //電郵
                    RoleName = $"{user.CompCd}-{user.RoleId}",
                    RoleNameList = rolelist            //權限下拉單
                                   .Select(x => new SelectListItem()
                    {
                        Text = $"{x.CompCd}-{x.RoleName}",
                        Value = $"{x.CompCd}-{x.RoleId}",
                    }),
                }));
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
                return(View("Edit", new MemberSetViewModel()));
            }
        }
Ejemplo n.º 4
0
        public JsonResult Get(TcmpdatApiViewModel data)
        {
            try
            {
                if (data == null)
                {
                    throw new ArgumentNullException($"no input data : {nameof(TastkndApiViewModel) }");
                }

                var con = new Conditions <DataBase.TCMPDAT>(data.pageSize, data.page);

                data.GetProperties()
                .Select(x => x.Avatar <AvatarAttribute>(data))
                .Where(x => x.Key != null)
                .ForEach(g => con.ConvertToFilter(g.Key.SubstituteName,
                                                  g.Key.ExpressionType,
                                                  g.Key.PredicateType,
                                                  g.Value));

                if (!string.IsNullOrEmpty(data.keyword))
                {
                    con.And(x => x.Comp_Cd.Contains(data.keyword) ||
                            x.Comp_Name.Contains(data.keyword));
                }



                con.Order(OrderType.Asc, x => x.Sort_Seq);

                #region DataRange

                var _user = (this.User.Identity as AspnetMvc.Models.PtcIdentity).currentUser;

                con.And(x => x.Comp_Cd == _user.CompCd);

                #endregion
                var meta = _baseRepo.GetList(con);

                IEnumerable <Select2> result = meta.Select(x => new Select2(x.CompCd, x.CompShort, x));


                return(Json(new { items = result, totalCount = meta.TotalCount }));
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
                return(Json(ex.Message));
            }
        }
        async Task <TResult?> GetResult <TResult>(HttpResponseMessage response)
        {
            var content = await response.Content.ReadAsStringAsync();

            try
            {
                var result = JsonConvert.DeserializeObject <TResult>(content);
                return(result);
            }
            catch (Exception ex)
            {
                response.Headers.TryGetValues("Content-Type", out var contentType);
                var errMsg =
                    $"Error parsing JSON content for type {typeof(TResult)}. Content Type: '{contentType}', content: {content}, error: {ex}";
                systemLog.Error(errMsg);
                throw;
            }
        }
Ejemplo n.º 6
0
        public ActionResult Index()
        {
            try
            {
                TassetsViewModel modal = new TassetsViewModel();

                return(View(modal));
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
                TempData["exMessage"] = ex.Message;
                return(View());
            }
        }
Ejemplo n.º 7
0
        public HttpResponseMessage VendorLogin(string Account, string Password, string UUID)
        {
            try
            {
                if (MethodHelper.IsNullOrEmpty(Account, Password, UUID))
                {
                    throw new ArgumentNullException($"未輸入帳號密碼");
                }

                //取得MD5資訊
                var md5Password = Identity.ClearPassword.GetMd5Hash(Password).ToUpper();

                TvenderTechnician result = _userService.VendorLogin(Account, md5Password, UUID);


                return(Request.CreateResponse(
                           HttpStatusCode.OK,
                           new JsonResult <TechnicianResultApiViewModel>(new TechnicianResultApiViewModel(result)
                {
                    Password = Password,
                    Token = TokenUtil <TvenderTechnician> .Create(new TvenderTechnician()
                    {
                        Account = result.Account,
                        Password = Password,
                        DeviceID = UUID,
                    })
                }, "登入成功", 1, true)));
            }
            catch (ArgumentOutOfRangeException ex)
            {
                return(Request.CreateResponse(
                           HttpStatusCode.OK,
                           new JsonResult <object>(new { clearUUID = true }, ex.ParamName, 1, true)));
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
                return(Request.CreateResponse(
                           HttpStatusCode.OK,
                           new JsonResult <TechnicianResultApiViewModel>(null, ex.Message, 1, false)));
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 自動通知技師:
        /// 通常在立案當下呼叫的
        /// </summary>
        /// <param name="Comp_Cd"></param>
        /// <param name="Sn"></param>
        /// <returns></returns>
        public Boolean AutoNotification(string Comp_Cd, string Sn)
        {
            _logger.Info($"立案自動通知-公司別:{Comp_Cd},案件編號:{Sn}");

            #region 驗證與取得資訊

            //取得案件
            Tcallog callog = base.GetCallog(Comp_Cd, Sn);

            //取得廠商及底下的技師群組
            var venderCon = new Conditions <DataBase.TVENDER>();

            venderCon.And(x => x.Comp_Cd == callog.CompCd &&
                          x.Vender_Cd == callog.VenderCd);

            _logger.Info($"立案自動通知-公司別:{callog.CompCd}");
            _logger.Info($"立案自動通知-廠商別:{callog.VenderCd}");


            venderCon.Include(x => x.TTechnicianGroup
                              .Select(g => g.TTechnicianGroupClaims
                                      .Select(y => y.TVenderTechnician)));

            Tvender vender = _venderRepo.Get(venderCon);

            if (vender == null)
            {
                _logger.Error($"查無廠商-廠商別:{callog.VenderCd}");
                throw new Exception($"查無廠商");
            }

            #endregion

            //找到可以被自動推播的群組
            IEnumerable <TtechnicianGroup> groups    = vender.TTechnicianGroup;
            List <TtechnicianGroup>        techGroup = new List <TtechnicianGroup>();
            techGroup.AddRange(groups.Where(x => x.Responsible_Do.Contains(callog.Do)).ToList());
            if (groups.Where(x => x.Responsible_Do.Contains(callog.Do)).Count() == 0)
            {
                //沒有對應的課群組才撈區群組
                techGroup.AddRange(groups.Where(x => x.Responsible_Zo.Contains(callog.Zo)).ToList());
            }
            techGroup = techGroup.Distinct().ToList();

            //取出群組內技師並過濾
            Dictionary <string, string> accounts = new Dictionary <string, string>();

            //確認廠商是否有建立技師
            var venderTech = new Conditions <DataBase.TVenderTechnician>();
            venderTech.And(x => x.Comp_Cd == callog.CompCd &&
                           x.Vender_Cd == callog.VenderCd);
            var technicians = _technicianRepo.GetList(venderTech);

            //有建立技師,沒有建立群組則自動建立進行推播


            if (technicians.Count != 0 && groups.ToList().Count == 0)
            {
                _logger.Error($"查無群組自動建立-廠商別:{callog.VenderCd}");
                //取得廠商所負責的區域
                var venderZO = new Conditions <DataBase.TVNDZO>();
                venderZO.And(x => x.Comp_Cd == callog.CompCd &&
                             x.Vender_Cd == callog.VenderCd);
                var vndzos = _vndzoRepo.GetList(venderZO);

                string ZO = "";
                string DO = "";

                vndzos?.ForEach(vndzo =>
                {
                    ZO += "," + vndzo.Zo;
                    //取得各區對應的課別
                    var ZOCODE = new Conditions <DataBase.TZOCODE>();
                    ZOCODE.And(x => x.Comp_Cd == vndzo.CompCd &&
                               x.Z_O == vndzo.Zo &&
                               x.Upkeep_Sts == "Y");
                    var zocodes = _zocodeRepo.GetList(ZOCODE);
                    zocodes?.ForEach(zocode =>
                    {
                        DO += "," + zocode.DoCd;
                    });
                });

                //新增群組
                var con = new Conditions <DataBase.TTechnicianGroup>();
                con.And(x => x.CompCd == callog.CompCd);
                con.And(x => x.VendorCd == callog.VenderCd);
                TtechnicianGroup TGroup = new TtechnicianGroup();
                TGroup.CompCd         = callog.CompCd;
                TGroup.VendorCd       = callog.VenderCd;
                TGroup.GroupName      = "系統產生";
                TGroup.Responsible_Zo = ZO.Substring(1);
                TGroup.Responsible_Do = DO.Substring(1);

                if (!_technicianGroupRepo.Add(con, TGroup))
                {
                    throw new Exception("[ERROR]=>自動新增群組時,新增失敗");
                }
                else
                {
                    //重新取得群組
                    vender = _venderRepo.Get(venderCon);
                    TtechnicianGroup group = vender.TTechnicianGroup.SingleOrDefault();

                    _logger.Info($"自動新增技師群組對應主檔開始");
                    var Claimscon = new Conditions <DataBase.TTechnicianGroupClaims>();
                    TtechnicianGroupClaims TClaims = new TtechnicianGroupClaims();
                    TClaims.Seq      = group.Seq;
                    TClaims.CompCd   = callog.CompCd;
                    TClaims.VendorCd = callog.VenderCd;
                    //新增技師群組對應主檔
                    technicians?.ForEach(technician =>
                    {
                        Claimscon.And(x => x.Seq == group.Seq);
                        Claimscon.And(x => x.CompCd == group.CompCd);
                        Claimscon.And(x => x.VendorCd == group.VendorCd);
                        Claimscon.And(x => x.Account == technician.Account);
                        TClaims.Account = technician.Account;
                        try
                        {
                            _technicianGroupClaimsRepo.Add(Claimscon, TClaims);
                        }
                        catch (Exception)
                        {
                            _logger.Error($"自動新增技師群組對應主檔時新增失敗-公司別:{callog.CompCd},廠商別:{callog.VenderCd},技師帳號:{technician.Account}");
                        }
                        Claimscon = new Conditions <DataBase.TTechnicianGroupClaims>();
                    });
                    _logger.Info($"自動新增技師群組對應主檔結束");


                    technicians?.ForEach(claim =>
                    {
                        var current = claim;

                        _logger.Info($"立案自動通知-組合物件-尋覽技師名稱:{current.Account}");

                        //啟用
                        if (current.Enable)
                        {
                            try
                            {
                                if (!accounts.Keys.Contains(current.Account))
                                {
                                    accounts.Add(current.Account, current.RegistrationID);
                                }
                            }
                            catch (Exception ex)
                            {
                                _logger.Error($"立案自動通知-技師帳號:{current.Account},放入推播清單錯誤,原因:{ex.Message}");
                            }
                        }
                    });
                }
            }
            else
            {
                techGroup?.ForEach(group =>
                {
                    _logger.Info($"立案自動通知-組合物件-尋覽群組代號:{group.Seq}");

                    group.TTechnicianGroupClaims?.ForEach(claim =>
                    {
                        var current = claim.TVenderTechnician;

                        _logger.Info($"立案自動通知-組合物件-尋覽技師名稱:{current.Account}");

                        //啟用
                        if (current.Enable)
                        {
                            try
                            {
                                if (!accounts.Keys.Contains(current.Account))
                                {
                                    accounts.Add(current.Account, current.RegistrationID);
                                }
                            }
                            catch (Exception ex)
                            {
                                _logger.Error($"立案自動通知-技師帳號:{current.Account},放入推播清單錯誤,原因:{ex.Message}");
                            }
                        }
                    });
                });
            }

            //更新TCALLOG.TimePoint
            //var callogcon = new Conditions<DataBase.TCALLOG>();
            //callogcon.And(x => x.Comp_Cd == callog.CompCd);
            //callogcon.And(x => x.Sn == callog.Sn);
            //callogcon.Allow(x => x.TimePoint);

            //if (!_callogRepo.Update(callogcon, new Tcallog()
            //{
            //    TimePoint = 1
            //}))
            //    throw new Exception("更新TCALLOG.TimePoint失敗");


            if (callog.TacceptedLog == null)
            {
                //準備通知-寫入待認養
                accounts.ForEach(account =>
                {
                    try
                    {
                        _logger.Info($"準備通知-寫入待認養 帳號:{account.Key}");

                        #region 更新資料

                        _technicianProvider.AddAwaitAcceptLog(callog.CompCd, callog.Sn, account.Key);

                        #endregion
                    }
                    catch (Exception ex)
                    {
                        _logger.Error($"準備通知-寫入待認養 帳號:{account},通知發生錯誤,原因:{ex.Message}");
                        if (ex.InnerException != null)
                        {
                            _logger.Error(ex.InnerException.Message);
                            if (ex.InnerException.InnerException != null)
                            {
                                _logger.Error(ex.InnerException.InnerException.Message);
                            }
                        }
                        _logger.Error(ex.StackTrace);
                    }
                });

                //準備推播
                accounts.ForEach(account =>
                {
                    try
                    {
                        _logger.Info($"準備推播 帳號:{account.Key}");

                        string storeName = getStoreName(callog.CompCd, callog.StoreCd);
                        string CallLevel = callog.CallLevel == "1" ? "普通" : "緊急";

                        #region 推播訊息

                        _notifyFactory.Exucte(new JPushRequest(
                                                  callog.CompCd,
                                                  callog.VenderCd)
                        {
                            Sn      = callog.Sn,
                            Content = $"您有一筆新案件待認養,案件編號:{callog.Sn} 店名:{storeName} 叫修等級:{CallLevel}",
                            Title   = "認養案件",
                            Extras  = new Dictionary <string, string>()
                            {
                                { "FeatureName", "VenderAccept" }
                            }
                        }, account.Key, account.Value);
                        #endregion
                    }
                    catch (Exception ex)
                    {
                        _logger.Error($"準備推播 帳號:{account},通知發生錯誤,原因:{ex.Message}");
                        if (ex.InnerException != null)
                        {
                            _logger.Error(ex.InnerException.Message);
                            if (ex.InnerException.InnerException != null)
                            {
                                _logger.Error(ex.InnerException.InnerException.Message);
                            }
                        }
                        _logger.Error(ex.StackTrace);
                    }
                });
            }

            return(true);
        }
Ejemplo n.º 9
0
        public ActionResult Getcallog(DataTablesReqModel <List <ChangeAssignedViewModel> > data)
        {
            var _user = ((PtcIdentity)this.User.Identity).currentUser;

            if (_user.CompCd == "")
            {
                _user.CompCd = "711";
            }
            DataTablesRespModel result = new DataTablesRespModel(data.draw);

            try
            {
                #region 取得所有區域
                Conditions <DataBase.TZOCODE> conZo = new Conditions <DataBase.TZOCODE>();
                conZo.And(x => x.Comp_Cd == _user.CompCd); //公司別
                var Zo = _TzocodeRepo.GetList(conZo).ToList();
                #endregion

                #region 取得未完修案件
                Conditions <DataBase.VW_MobileCallogNoFinish> conCallog = new Conditions <DataBase.VW_MobileCallogNoFinish>();
                conCallog.And(x => x.Comp_Cd == _user.CompCd);               //公司別
                conCallog.And(x => x.Vender_Cd == _user.VenderCd);           //廠商
                conCallog.And(x => x.Close_Sts == (byte)CloseSts.process);   //剛立案
                conCallog.And(x => x.TimePoint >= (byte)TimePoint.Accepted); //timepoint>=2
                conCallog.And(x => x.TimePoint < (byte)TimePoint.Finish);    //timepoint<4
                data.order?.ForEach(x =>
                {
                    if (data.columns[x.column].name == "Zo_Name")
                    {
                        conCallog.Order(x.dir, "Z_O");
                    }
                    else if (data.columns[x.column].name == "Do_Name")
                    {
                        conCallog.Order(x.dir, "D_O");
                    }
                    else
                    {
                        conCallog.Order(x.dir, data.columns[x.column].name);
                    }
                });
                var Data = _VWMobileCallogNoFinishRepo.GetList(conCallog);
                #endregion
                int PageIndex = (data.start / data.length);
                PagedList <MobileCallogSearch> meta = new PagedList <MobileCallogSearch>(Data, PageIndex, data.length);
                result.data = meta.Select(x => new ChangeAssignedViewModel(x,
                                                                           Zo.Where(y => y.ZoCd == x.Zo && y.DoCd == "").Select(z => z.ZoName).FirstOrDefault(),
                                                                           Zo.Where(y => y.ZoCd == x.Zo && y.DoCd == x.Do).Select(z => z.DoName).FirstOrDefault()).colData).ToArray();
                result.TotalCount(conCallog.TotalCount);
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                if (ex.InnerException != null)
                {
                    _logger.Error(ex.InnerException.Message);
                    if (ex.InnerException.InnerException != null)
                    {
                        _logger.Error(ex.InnerException.InnerException.Message);
                    }
                }
                result.error = ex.Message;
            }
            return(Json(result));
        }
Ejemplo n.º 10
0
        public ActionResult Index()
        {
            var _user = ((PtcIdentity)this.User.Identity).currentUser;
            var AutheticationManager = HttpContext.GetOwinContext().Authentication;

            try
            {
                return(View(new TechnicianViewModel()
                {
                    CompCd = _user.CompCd,
                    VenderCd = _user.VenderCd,
                    CompName = _user.CompShort,
                    VendorName = _user.VenderName,
                }));
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
                if (ex.InnerException != null)
                {
                    _logger.Error(ex.InnerException.Message);
                    if (ex.InnerException.InnerException != null)
                    {
                        _logger.Error(ex.InnerException.InnerException.Message);
                    }
                }
                AutheticationManager.SignOut();
                TempData["ErrorMessage"] = ex.Message;
                return(RedirectToAction("Login", "Account"));
            }
        }
Ejemplo n.º 11
0
        public ActionResult GetList(DataTablesReqModel <List <TechnicianGroupViewModel> > Data)
        {
            List <TechnicianGroupViewModel> models = Data.criteria;

            DataTablesRespModel result = new DataTablesRespModel(Data.draw);

            try
            {
                if (Data.criteria == null)
                {
                    throw new Exception("沒有條件,無法查詢");
                }

                Conditions <DataBase.TTechnicianGroup> con = new Conditions <DataBase.TTechnicianGroup>(Data.length, (Data.start / Data.length));

                models?.ForEach(model =>
                {
                    var component = new List <Expression <Func <DataBase.TTechnicianGroup, Boolean> > >();

                    model.GetProperties()?
                    .Select(x => x.Avatar <AvatarAttribute>(model))
                    .Where(x => x.Key != null)
                    .ForEach(g =>
                    {
                        component.Add(con.CombinationExpression(
                                          g.Key.SubstituteName,
                                          g.Key.ExpressionType,
                                          g.Value));
                    });

                    con.ConvertToMultiFilter(component);
                });

                Data.order?.ForEach(x =>
                {
                    con.Order(x.dir, Data.columns[x.column].name);
                });

                //con.Include(x => x.TVENDER.TCMPDAT);
                #region DataRange

                var _user = (this.User.Identity as AspnetMvc.Models.PtcIdentity).currentUser;

                con.And(x => x.TVENDER.Comp_Cd == _user.CompCd);

                if (_user.DataRange?.VendorCd != null)
                {
                    con.And(x => _user.DataRange.VendorCd.Contains(x.VendorCd));
                }

                #endregion
                var list      = _technicianGroupRepo.GetList(con);
                int PageIndex = (Data.start / Data.length);
                PagedList <TtechnicianGroup> meta = new PagedList <TtechnicianGroup>(list, PageIndex, Data.length);

                var conZo = new Conditions <DataBase.TZOCODE>();
                conZo.And(x => x.Comp_Cd == _user.CompCd);
                PagedList <Tzocode> Zo = _TzocodeRepo.GetList(conZo);

                result.data = meta.Select(x => new TechnicianGroupResultViewModel(x, Zo).colData).ToArray();

                result.TotalCount(con.TotalCount);
            }
            catch (AutoMapper.AutoMapperMappingException ex)
            {
                _logger.Error(ex);
                if (ex.InnerException != null)
                {
                    _logger.Error(ex.InnerException.Message);
                    if (ex.InnerException.InnerException != null)
                    {
                        _logger.Error(ex.InnerException.InnerException.Message);
                    }
                }
                result.error = ex.InnerException.Message;
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
                if (ex.InnerException != null)
                {
                    _logger.Error(ex.InnerException.Message);
                    if (ex.InnerException.InnerException != null)
                    {
                        _logger.Error(ex.InnerException.InnerException.Message);
                    }
                }
                result.error = ex.Message;
            }
            return(Json(result));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 新增照片
        /// </summary>
        public void AddImg(Tcallog input)
        {
            DataBase.SETENG_Entities db = new DataBase.SETENG_Entities();
            var resault = db.TCALIMG.Where(x => x.Comp_Cd == input.CompCd && x.Sn == input.Sn);

            if (resault.ToList().Count > 0)
            {
                foreach (var seq in resault.Select(x => x.File_Seq).ToList())
                {
                    var query = db.TUpFile.Where(x => x.File_Seq == seq);
                    foreach (var item in query)
                    {
                        bool success = _getCallLogFile.DelFile(input.Sn, input.CompCd, item.File_Name);
                        if (!success)
                        {
                            _logger.Error("圖片刪除錯誤-檔名: " + item.File_Name);
                        }
                    }
                    db.TUpFile.RemoveRange(query);
                }
                db.TCALIMG.RemoveRange(resault);
                db.SaveChanges();
            }
            foreach (var img in input.ImgBeforeFix)
            {
                int index = 0;
                var table = db.TCALIMG.Where(x => x.Comp_Cd == input.CompCd && x.Sn == input.Sn);
                if (table.ToList().Count == 0)
                {
                    index = 1;
                }
                else
                {
                    index = table.Max(x => x.Seq);
                    index = index + 1;
                }
                DataBase.TUpFile item = new DataBase.TUpFile();
                item.Create_Date = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                item.Create_User = input.AcceptedName;
                item.Doc_Type    = "jpg";
                item.File_Name   = String.Format("{0}-{1}-{2}.jpg", input.CompCd, input.Sn, index);
                item.Pgm_Id      = "手機上傳";
                item.File_Size   = 0;
                db.TUpFile.Add(item);
                db.SaveChanges();

                DataBase.TUpFile Upfile  = db.TUpFile.Where(x => x.File_Name == item.File_Name).FirstOrDefault();
                DataBase.TCALIMG itemImg = new DataBase.TCALIMG();
                itemImg.Comp_Cd  = input.CompCd;
                itemImg.File_Seq = Upfile.File_Seq;
                itemImg.Img_Type = ((int)ImgType.BeforeFix).ToString();
                itemImg.Seq      = (byte)index;
                itemImg.Sn       = input.Sn;
                db.TCALIMG.Add(itemImg);
                db.SaveChanges();

                uploadImage(img, input.Sn, input.CompCd, item.File_Name);
            }
            foreach (var img in input.ImgAfterFix)
            {
                int index = 0;
                var table = db.TCALIMG.Where(x => x.Comp_Cd == input.CompCd && x.Sn == input.Sn);
                if (table.ToList().Count == 0)
                {
                    index = 1;
                }
                else
                {
                    index = table.Max(x => x.Seq);
                    index = index + 1;
                }
                DataBase.TUpFile item = new DataBase.TUpFile();
                item.Create_Date = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                item.Create_User = input.AcceptedName;
                item.Doc_Type    = "jpg";
                item.File_Name   = String.Format("{0}-{1}-{2}.jpg", input.CompCd, input.Sn, index);
                item.Pgm_Id      = "手機上傳";
                item.File_Size   = 0;
                db.TUpFile.Add(item);
                db.SaveChanges();

                DataBase.TUpFile Upfile  = db.TUpFile.Where(x => x.File_Name == item.File_Name).FirstOrDefault();
                DataBase.TCALIMG itemImg = new DataBase.TCALIMG();
                itemImg.Comp_Cd  = input.CompCd;
                itemImg.File_Seq = Upfile.File_Seq;
                itemImg.Img_Type = ((int)ImgType.AfterFix).ToString();
                itemImg.Seq      = (byte)index;
                itemImg.Sn       = input.Sn;
                db.TCALIMG.Add(itemImg);
                db.SaveChanges();
                uploadImage(img, input.Sn, input.CompCd, item.File_Name);
            }

            foreach (var img in input.Img)
            {
                int index = 0;
                var table = db.TCALIMG.Where(x => x.Comp_Cd == input.CompCd && x.Sn == input.Sn);
                if (table.ToList().Count == 0)
                {
                    index = 1;
                }
                else
                {
                    index = table.Max(x => x.Seq);
                    index = index + 1;
                }
                DataBase.TUpFile item = new DataBase.TUpFile();
                item.Create_Date = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                item.Create_User = input.AcceptedName;
                item.Doc_Type    = "jpg";
                item.File_Name   = String.Format("{0}-{1}-{2}.jpg", input.CompCd, input.Sn, index);
                item.Pgm_Id      = "手機上傳";
                item.File_Size   = 0;
                db.TUpFile.Add(item);
                db.SaveChanges();

                DataBase.TUpFile Upfile  = db.TUpFile.Where(x => x.File_Name == item.File_Name).FirstOrDefault();
                DataBase.TCALIMG itemImg = new DataBase.TCALIMG();
                itemImg.Comp_Cd  = input.CompCd;
                itemImg.File_Seq = Upfile.File_Seq;
                itemImg.Img_Type = ((int)ImgType.Workorder).ToString();
                itemImg.Seq      = (byte)index;
                itemImg.Sn       = input.Sn;
                db.TCALIMG.Add(itemImg);
                db.SaveChanges();
                uploadImage(img, input.Sn, input.CompCd, item.File_Name);
            }
            foreach (var img in input.ImgSignature)
            {
                int index = 0;
                var table = db.TCALIMG.Where(x => x.Comp_Cd == input.CompCd && x.Sn == input.Sn);
                if (table.Count() == 0)
                {
                    index = 1;
                }
                else
                {
                    index = table.Max(x => x.Seq);
                    index = index + 1;
                }
                DataBase.TUpFile item = new DataBase.TUpFile();
                item.Create_Date = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                item.Create_User = input.AcceptedName;
                item.Doc_Type    = "jpg";
                item.File_Name   = String.Format("{0}-{1}-{2}.jpg", input.CompCd, input.Sn, index);
                item.Pgm_Id      = "手機上傳";
                item.File_Size   = 0;
                db.TUpFile.Add(item);
                db.SaveChanges();

                DataBase.TUpFile Upfile  = db.TUpFile.Where(x => x.File_Name == item.File_Name).FirstOrDefault();
                DataBase.TCALIMG itemImg = new DataBase.TCALIMG();
                itemImg.Comp_Cd  = input.CompCd;
                itemImg.File_Seq = Upfile.File_Seq;
                itemImg.Img_Type = ((int)ImgType.Signature).ToString();
                itemImg.Seq      = (byte)index;
                itemImg.Sn       = input.Sn;
                db.TCALIMG.Add(itemImg);
                db.SaveChanges();

                uploadImage(img, input.Sn, input.CompCd, item.File_Name);
            }
        }