/// <summary> /// 單一更新 /// </summary> /// <param name="conditions"></param> /// <param name="data"></param> /// <returns></returns> public Boolean Update(Conditions <T1> conditions, T2 data) { using (DataBase.SETENG_Entities db = new DataBase.SETENG_Entities()) { db.Configuration.LazyLoadingEnabled = false; var query = db.Set <T1>().AsQueryable(); conditions.Includes?.ForEach(x => query = query.Include(x)); query = query.AsExpandable().Where(conditions.GetPredicate()); var original = query.FirstOrDefault(); if (original == null) { throw new NullReferenceException($"[UPDATE] error. data is not found : {typeof(T1)} ."); } var noval = Mapper.Map <T1>(data); UpdateProcess(original, noval, conditions.AllowProps); return(db.SaveChanges() > 0); } }
/// <summary> /// 紀錄推播訊息 /// </summary> /// <param name="Sn"></param> /// <param name="Account"></param> /// <param name="Content"></param> /// <returns></returns> public Boolean RecordPush(string Sn, IPushRequest data) { using (DataBase.SETENG_Entities db = new DataBase.SETENG_Entities()) { db.Configuration.LazyLoadingEnabled = false; var exist = db.TCallLogRecord.SingleOrDefault(x => x.SN == Sn); if (exist == null) { db.TCallLogRecord.Add(new DataBase.TCallLogRecord() { SN = Sn, RecordRemark = JsonConvert.SerializeObject(new List <IPushRequest>() { data }), RecordDatetime = DateTime.Now, }); } else { var records = JsonConvert.DeserializeObject <List <IPushRequest> >(exist.RecordRemark); records.Add(data); exist.RecordRemark = JsonConvert.SerializeObject(records); } return(db.SaveChanges() > 0); } }
/// <summary> /// 單一新增(排除query.Any) /// </summary> /// <param name="conditions"></param> /// <param name="data"></param> /// <returns></returns> public Boolean Insert(Conditions <T1> conditions, T2 data) { using (DataBase.SETENG_Entities db = new DataBase.SETENG_Entities()) { db.Configuration.LazyLoadingEnabled = false; var query = db.Set <T1>().AsQueryable(); conditions.Includes?.ForEach(x => query = query.Include(x)); query = query.AsExpandable().Where(conditions.GetPredicate()); //if (query.Any()) { throw new NullReferenceException($"[ADD] error. data is Exist : {typeof(T1)} ."); } var entity = Mapper.Map <T1>(data); db.Set <T1>().Add(entity); return(db.SaveChanges() > 0); } }
/// <summary> /// (單一/整批)刪除 /// </summary> /// <param name="conditions"></param> /// <returns></returns> public Boolean Remove(Conditions <T1> conditions) { using (DataBase.SETENG_Entities db = new DataBase.SETENG_Entities()) { db.Configuration.LazyLoadingEnabled = false; var query = db.Set <T1>().AsQueryable(); conditions.Includes?.ForEach(x => query = query.Include(x)); query = query.AsExpandable().Where(conditions.GetPredicate()); if (!query.Any()) { throw new NullReferenceException($"[REMOVE] error. data is not found : {typeof(T1)} ."); } db.Set <T1>().RemoveRange(query); return(db.SaveChanges() > 0); } }
///// <summary> ///// 刪除技師圖片 ///// </summary> ///// <param name="Data"></param> ///// <param name="Path"></param> ///// <returns></returns> //public Boolean DeleteImg(TvenderTechnician Data, string filePath) //{ // using (DataBase.SpccEngCCSysEntities db = new DataBase.SpccEngCCSysEntities()) // { // db.Configuration.LazyLoadingEnabled = false; // var query = db.TVenderTechnician // .SingleOrDefault(x => x.Account == Data.Account && // x.Vender_Cd == Data.VenderCd && // x.Comp_Cd == Data.CompCd); // if (query == null) // throw new NullReferenceException($"[ERROR]=> 刪除技師圖片找不到相關資訊"); // var technicianImgPath = JsonConvert.DeserializeObject<List<string>>(query.TechnicianImgPath); // var stickerImgPath = JsonConvert.DeserializeObject<List<string>>(query.StickerImgPath); // var LicenseImgPath = JsonConvert.DeserializeObject<List<string>>(query.LicenselmgPath); // if (technicianImgPath.Contains(filePath)) // { // technicianImgPath.Remove(filePath); // query.TechnicianImgPath = JsonConvert.SerializeObject(technicianImgPath); // } // else if (stickerImgPath.Contains(filePath)) // { // stickerImgPath.Remove(filePath); // query.StickerImgPath = JsonConvert.SerializeObject(stickerImgPath); // } // else if (LicenseImgPath.Contains(filePath)) // { // LicenseImgPath.Remove(filePath); // query.LicenselmgPath = JsonConvert.SerializeObject(LicenseImgPath); // } // else // throw new IndexOutOfRangeException($"[ERROR]=> 刪除技師圖片,圖片位址對應錯誤"); // return db.SaveChanges() > 0; // } //} /// <summary> /// 新增可受理案件 /// </summary> /// <returns></returns> public Boolean AddAwaitAcceptLog(string CompCd, string Sn, string Account) { try { using (DataBase.SETENG_Entities db = new DataBase.SETENG_Entities()) { db.Configuration.LazyLoadingEnabled = false; var callog = db.TCALLOG .SingleOrDefault(x => x.Comp_Cd == CompCd && x.Sn == Sn); if (callog == null) { throw new NullReferenceException("[ERROR]=>技師新增可受理案件時,找不到案件資訊"); } var technician = db.TVenderTechnician .Include("TCALLOG") .SingleOrDefault(x => x.Comp_Cd == callog.Comp_Cd && x.Vender_Cd == callog.Vender_Cd && x.Account == Account); if (technician == null) { throw new NullReferenceException("[ERROR]=>技師新增可受理案件時,找不到技師資訊"); } technician.TCALLOG.Add(callog); return(db.SaveChanges() > 0); } } catch (Exception ex) { return(false); } }
/// <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); } }