public ActionResult UpdateNotify([FromRoute] decimal id) { System.Web.Http.HttpError errorHttp = null; IDbContextTransaction tran = _context.Database.BeginTransaction(); try { var query = from d in _context.D_NOTIFYS where d.NOTIFY_ID == id select d; if (!query.Any()) { errorHttp = new System.Web.Http.HttpError("Notify is not exists!"); return(Ok(new Result { Status = 404, Message = errorHttp.Message, Data = false })); } D_NOTIFY notify = query.Single(); notify.READED_FLG = (int)ReadedFlg.Readed; notify.UPD_DATETIME = Utility.GetSysDateTime(); _context.SaveChanges(); // Commit transaction. tran.Commit(); errorHttp = new System.Web.Http.HttpError("Update notify is success!"); return(Ok(new Result { Status = 200, Message = errorHttp.Message, Data = true })); } catch (System.Exception) { // Rollback transaction. tran.Rollback(); errorHttp = new System.Web.Http.HttpError("Update notify is not success!"); return(Ok(new Result { Status = 404, Message = errorHttp.Message, Data = false })); } }
/// <summary> /// Update user/ company infomation. /// </summary> /// <param name="db">DataContext.</param> /// <param name="userEntity">User entity</param> /// <returns>Ok: true, Fail: false</returns> public static bool UpdateUser(AloaiDataContext db, UserEntity userEntity) { var query = from d in db.M_USERS where d.USER_ID == userEntity.userId select d; M_USER user = query.Single(); user.PHONE_NUMBER = userEntity.phoneNumber; user.NAME = userEntity.name; if (userEntity.avatar != null) { string avartaPath = string.Empty; if (Utility.UploadAvatar(db, userEntity.userId, userEntity.avatar, userEntity.avatar.path, out avartaPath)) { user.AVATAR = avartaPath; } } user.MODE_DEFAULT = userEntity.modeDefault; user.UPD_DATETIME = Utility.GetSysDateTime(); List <T_PARTNER_CATALOG_UNIT> workerList = new List <T_PARTNER_CATALOG_UNIT>(); db.SaveChanges(); return(true); }
public ActionResult InsertContactHistory(ContactEntity entity) { System.Web.Http.HttpError errorHttp = null; if (entity == null) { errorHttp = new System.Web.Http.HttpError("ContactEntity is not found!"); return(Ok(new Result { Status = 404, Message = errorHttp.Message, Data = false })); } IDbContextTransaction transaction = _context.Database.BeginTransaction(); try { // Open transaction. D_CONTACT contact = new D_CONTACT(); contact.USER_RECIEVE_ID = entity.userRecieveId; contact.REG_MODE_USER = entity.contactModeUser; contact.CONTACT_USER_ID = entity.contactUserId; contact.CATALOG_CD = entity.catalogCd; contact.CONTACT_DATE = Utility.GetSysDateTime(); _context.D_CONTACTS.Add(contact); _context.SaveChanges(); // Commit transaction. transaction.Commit(); errorHttp = new System.Web.Http.HttpError("Insert is success!"); return(Ok(new Result { Status = 200, Message = errorHttp.Message, Data = true })); } catch { // Rollback transaction. transaction.Rollback(); System.Web.Http.HttpError error = new System.Web.Http.HttpError("Error system!"); return(Ok(new Result { Status = 404, Message = error.Message, Data = false })); } }
public ActionResult CreateJob(JobEntity job) { var item = new D_JOB { USER_ID = job.userId, SUGGEST_ID = job.suggestId, LATITUDE = job.location.latitude, LONGITUDE = job.location.longitude, CANCEL_FLG = 0, RENEW_NUM = 0, REG_DATETIME = Utility.GetSysDateTime(), }; _context.D_JOBS.Add(item); _context.SaveChanges(); return(Ok(new Result { Status = 200, Message = string.Empty, Data = true })); }
/// <summary> /// Update token /// </summary> /// <param name="userId">user Id</param> /// <param name="token">Token string</param> /// <returns>Ok: true, Fail: false</returns> public bool UpdateToken(AloaiDataContext context, decimal userId, string token) { var query = from d in context.M_USERS where d.USER_ID == userId select d; if (query.Any()) { M_USER user = query.Single(); user.TOKEN = token; user.UPD_DATETIME = Utility.GetSysDateTime(); context.SaveChanges(); return(true); } return(false); }
public ActionResult InsertQuestion(QuestionEntity questionEntity) { IDbContextTransaction tran = _context.Database.BeginTransaction(); try { M_QUESTION question = new M_QUESTION(); question.USER_ID = questionEntity.userId; question.SUBJECT = questionEntity.subject; question.CONTENT = questionEntity.content; question.QUESTION_DATE = Utility.GetSysDateTime(); question.REG_DATETIME = Utility.GetSysDateTime(); _context.M_QUESTIONS.Add(question); _context.SaveChanges(); // Commit transaction. tran.Commit(); System.Web.Http.HttpError errorHttp = new System.Web.Http.HttpError("Insert is success!"); return(Ok(new Result { Status = 200, Message = errorHttp.Message, Data = true })); } catch { // Rollback transaction. tran.Rollback(); System.Web.Http.HttpError error = new System.Web.Http.HttpError("Error system!"); return(Ok(new Result { Status = 404, Message = error.Message, Data = true })); } }
public ActionResult UpdateFixLocation(decimal userId, decimal fixLocationFlg) { using (IDbContextTransaction tran = _context.Database.BeginTransaction()) { try { var queryPartner = from d in _context.M_PARTNER_INFOS where d.USER_ID == userId select d; if (queryPartner.Any()) { M_PARTNER_INFO partner = queryPartner.Single(); partner.FIX_LOCATION_FLG = fixLocationFlg; partner.UPD_DATETIME = Utility.GetSysDateTime(); _context.SaveChanges(); tran.Commit(); } return(Ok(new Result { Status = 200, Message = string.Empty, Data = true })); } catch (Exception) { tran.Rollback(); } } return(Ok(new Result { Status = 404, Message = string.Empty, Data = false })); }
public ActionResult UpdateHirerInfo(HirerInfoEntity hirer) { var query = from d in _context.M_USERS where d.USER_ID == hirer.userId select d; if (query.Any()) { M_USER upd = query.Single(); upd.NAME = hirer.name; string avartaPath; if (Utility.UploadAvatar(_context, hirer.userId, hirer.avatar, hirer.avatar.path, out avartaPath)) { upd.AVATAR = avartaPath; } upd.UPD_DATETIME = Utility.GetSysDateTime(); _context.SaveChanges(); HirerInfoEntity hirerInfo = Utility.GetHirerInfo(_context, hirer.userId); return(Ok(new Result { Status = 200, Message = string.Empty, Data = hirerInfo })); } return(Ok(new Result { Status = 404, Message = string.Empty, Data = null })); }
public ActionResult InsertEstimation(ReviewEntity entity) { System.Web.Http.HttpError errorHttp = null; if (entity == null) { errorHttp = new System.Web.Http.HttpError("EstimationEntity is not found!"); return(Ok(new Result { Status = 404, Message = errorHttp.Message, Data = null })); } IDbContextTransaction tran = _context.Database.BeginTransaction(); try { var query = from d in _context.D_REVIEWS where d.CONTACT_ID == entity.contactId && d.REVIEW_MODE_USER == (int)entity.reviewModeUser select d; if (query.Any()) { errorHttp = new System.Web.Http.HttpError("Estimation is exists!"); return(Ok(new Result { Status = 404, Message = errorHttp.Message, Data = null })); } decimal userReceiveId; decimal receiveModeUser; D_REVIEW estimation = new D_REVIEW(); estimation.CONTACT_ID = entity.contactId; estimation.REVIEW_USER_ID = entity.reviewUserId; estimation.REVIEW_MODE_USER = entity.reviewModeUser; estimation.REVIEW_DATE = Utility.GetSysDateTime(); estimation.SCORE = entity.score.Value; estimation.COMMENT = entity.comment; _context.D_REVIEWS.Add(estimation); _context.SaveChanges(); if (!UpdateScore(_context, entity.contactId, entity.score.Value, entity.reviewModeUser)) { // Rollback transaction. tran.Rollback(); errorHttp = new System.Web.Http.HttpError("Insert is not success!"); return(Ok(new Result { Status = 404, Message = errorHttp.Message, Data = null })); } if (entity.reviewModeUser == (decimal)Mode.Hirer) { var queryWorker = from d in _context.V_CONTACT_INFOS where d.CONTACT_ID == entity.contactId select d.WORKER_ID; if (!queryWorker.Any()) { // Rollback transaction. tran.Rollback(); errorHttp = new System.Web.Http.HttpError("Update is not success!"); return(Ok(new Result { Status = 404, Message = errorHttp.Message, Data = null })); } userReceiveId = queryWorker.Single(); receiveModeUser = (decimal)Mode.Partner; } else { var queryHirer = from d in _context.V_CONTACT_INFOS where d.CONTACT_ID == entity.contactId select d.HIRER_ID; if (!queryHirer.Any()) { // Rollback transaction. tran.Rollback(); errorHttp = new System.Web.Http.HttpError("Update is not success!"); return(Ok(new Result { Status = 404, Message = errorHttp.Message, Data = null })); } userReceiveId = queryHirer.Single(); receiveModeUser = (decimal)Mode.Hirer; } // Insert notify. if (!Utility.InsertNotify(_context, (int)NotifyType.Estimation, entity.contactId, entity.reviewUserId, userReceiveId, receiveModeUser)) { // Rollback transaction. tran.Rollback(); errorHttp = new System.Web.Http.HttpError("Update is not success!"); return(Ok(new Result { Status = 404, Message = errorHttp.Message, Data = null })); } // Commit transaction. tran.Commit(); errorHttp = new System.Web.Http.HttpError("Insert is success!"); return(Ok(new Result { Status = 200, Message = errorHttp.Message, Data = null })); } catch (Exception ex) { // Rollback transaction. tran.Rollback(); System.Web.Http.HttpError error = new System.Web.Http.HttpError(ex.Message); return(Ok(new Result { Status = 404, Message = error.Message, Data = null })); } }
/// <summary> /// Upload image to hosting. /// </summary> /// <param name="db">DataContext</param> /// <param name="objectId">Object ID</param> /// <param name="objectType">Object type</param> /// <param name="imageInfoEntity">Image info entity</param> /// <returns>Ok: true, Fail: false</returns> public static bool UploadImage(AloaiDataContext db, decimal objectId, ImageType objectType, List <ImageInfoEntity> imageInfoEntity) { if (imageInfoEntity == null || imageInfoEntity.Count == 0) { if (!RemoveImage(db, objectId, objectType)) { return(false); } return(true); } int index = 0; var delQuery = from d in db.M_IMAGE_DETAILS where d.OBJECT_ID == objectId && d.OBJECT_TYPE == (int)objectType select d; // Delete image not used. if (delQuery.Any()) { List <M_IMAGE_DETAIL> list = delQuery.ToList(); foreach (M_IMAGE_DETAIL del in list) { var exists = from d in imageInfoEntity where Path.GetFileName(d.path.Trim('\"')) == del.IMAGE_NAME select d; if (!exists.Any()) { string path = $"Upload/"; string fileName = Path.GetFileName(del.IMAGE_PATH); string directoryName = AppDomain.CurrentDomain.BaseDirectory + path; string ext = Path.GetExtension(del.IMAGE_PATH); fileName = System.IO.Path.Combine(directoryName, fileName) + ext; // Check if file exists with its full path if (File.Exists(fileName)) { // If file found, delete it. File.Delete(fileName); } } db.M_IMAGE_DETAILS.Remove(del); } } foreach (ImageInfoEntity imageInfo in imageInfoEntity) { if (!string.IsNullOrEmpty(imageInfo.path)) { continue; } index++; var thisFileName = Path.GetFileName(imageInfo.path.Trim('\"')); M_IMAGE_DETAIL image = new M_IMAGE_DETAIL(); image.OBJECT_ID = objectId; image.OBJECT_TYPE = (int)objectType; image.ROW_NO = index; image.IMAGE_NAME = Path.GetFileName(imageInfo.path); image.IMAGE_PATH = imageInfo.path; db.M_IMAGE_DETAILS.Add(image); } db.SaveChanges(); return(true); }
/// <summary> /// Insert notify. /// </summary> /// <param name="db">PartTimeDataClassesDataContext</param> /// <param name="notifyType">Notify type</param> /// <param name="id">Object ID</param> /// <param name="userSendId">User send ID</param> /// <param name="userReceiveId">User receive ID</param> /// <param name="receiveModeUser">Receive mode user</param> /// <returns>Success: True; Fail: False</returns> public static bool InsertNotify(AloaiDataContext db, decimal notifyType, decimal id, decimal userSendId , decimal userReceiveId, decimal receiveModeUser) { try { string senderName = string.Empty; // Check User receive notify leaved company but job is exists. // If true is not receive notify. if (notifyType != (int)NotifyType.System) { var queryUser = from d in db.M_USERS where d.USER_ID == userReceiveId select d; if (!queryUser.Any()) { return(true); } var queryExchange = from d in db.V_CONTACT_INFOS where d.CONTACT_ID == id select d; if (!queryExchange.Any()) { return(true); } } D_NOTIFY notify = new D_NOTIFY(); notify.NOTIFY_TYPE = notifyType; notify.OBJECT_ID = id; notify.USER_SEND_ID = userSendId; notify.USER_RECIEVE_ID = userReceiveId; notify.RECEIVE_MODE_USER = receiveModeUser; notify.READED_FLG = (int)ReadedFlg.New; notify.REG_DATETIME = GetSysDateTime(); notify.NOTIFY_DATE = GetSysDateTime(); notify.CONTENT = string.Empty; var query = from d in db.M_USERS where d.USER_ID == userSendId select d; if (!query.Any()) { return(false); } M_USER user = query.Single(); notify.CONTENT = user.NAME; db.D_NOTIFYS.Add(notify); db.SaveChanges(); } catch { return(false); } return(true); }
/// <summary> /// Upload image to hosting. /// </summary> /// <param name="db">DataContext</param> /// <param name="objectId">Object ID</param> /// <param name="objectType">Object type</param> /// <param name="imageInfoEntity">Image info entity</param> /// <returns>Ok: true, Fail: false</returns> public static bool UploadAvatar(AloaiDataContext db, decimal objectId, ImageInfoEntity avatar, string imagePath, out string avartaPath) { ImageType objectType = ImageType.Avatar; avartaPath = avatar.path; if (avatar != null && !string.IsNullOrEmpty(avatar.path)) { string path = $"Upload/"; string fileName = Path.GetFileName(avatar.path); string directoryName = AppDomain.CurrentDomain.BaseDirectory + path; string ext = Path.GetExtension(avatar.path); fileName = System.IO.Path.Combine(directoryName, fileName) + ext; if (File.Exists(fileName)) { var delQuery = from d in db.M_IMAGE_DETAILS where d.OBJECT_ID == objectId && d.OBJECT_TYPE == (int)objectType select d; // Delete image not used. if (delQuery.Any()) { M_IMAGE_DETAIL list = delQuery.Single(); if (avatar.path == list.IMAGE_PATH) { return(true); } // Check if file exists with its full path if (File.Exists(list.IMAGE_PATH)) { // If file found, delete it. File.Delete(list.IMAGE_PATH); } db.M_IMAGE_DETAILS.Remove(list); } if (avatar.image != null) { var thisFileName = Path.GetFileName(avatar.path.Trim('\"')); M_IMAGE_DETAIL image = new M_IMAGE_DETAIL(); image.OBJECT_ID = objectId; image.OBJECT_TYPE = (int)objectType; image.ROW_NO = 1; image.IMAGE_NAME = Path.GetFileName(thisFileName); image.IMAGE_PATH = avatar.path; avartaPath = avatar.path; db.M_IMAGE_DETAILS.Add(image); } db.SaveChanges(); } } return(true); }
/// <summary> /// Update user/ company infomation. /// </summary> /// <param name="db">DataContext.</param> /// <param name="userEntity">User entity</param> /// <returns>Ok: true, Fail: false</returns> public static bool UpdatePartner(AloaiDataContext db, PartnerEntity partnerEntity) { var query = from d in db.M_USERS where d.USER_ID == partnerEntity.userId select d; M_USER user = query.Single(); //user.PHONE_NUMBER = partnerEntity.PhoneNumber; user.NAME = partnerEntity.name; if (partnerEntity.avatar != null && !string.IsNullOrEmpty(partnerEntity.avatar.path)) { string avartaPath; if (Utility.UploadAvatar(db, partnerEntity.userId, partnerEntity.avatar, partnerEntity.avatar.path, out avartaPath)) { user.AVATAR = avartaPath; } } user.UPD_DATETIME = Utility.GetSysDateTime(); db.SaveChanges(); var queryPartner = from d in db.M_PARTNER_INFOS where d.USER_ID == partnerEntity.userId select d; if (queryPartner.Any()) { M_PARTNER_INFO partner = queryPartner.Single(); partner.INTRODUCE = partnerEntity.introduce; partner.FIX_LOCATION_FLG = partnerEntity.fixLocationFlg ? 1 : 0; if (partnerEntity.fixLocationFlg) { partner.LONGITUDE = partnerEntity.location.longitude; partner.LATITUDE = partnerEntity.location.latitude; partner.ADDRESS = partnerEntity.location.address; } else { partner.LONGITUDE = string.Empty; partner.LATITUDE = string.Empty; partner.ADDRESS = string.Empty; } partner.UPD_DATETIME = Utility.GetSysDateTime(); db.SaveChanges(); } var queryDel = from d in db.T_PARTNER_CATALOG_UNITS where d.USER_ID == partnerEntity.userId select d; if (queryDel.Any()) { db.T_PARTNER_CATALOG_UNITS.RemoveRange(queryDel.ToList()); db.SaveChanges(); } if (partnerEntity.partnerCatalog != null) { T_PARTNER_CATALOG_UNIT worker = new T_PARTNER_CATALOG_UNIT(); worker.USER_ID = partnerEntity.userId; worker.CATALOG_CD = partnerEntity.partnerCatalog.catalog.catalogCd; worker.COST = partnerEntity.partnerCatalog.cost; worker.UNIT_CD = partnerEntity.partnerCatalog.unit.unitCd; worker.REG_DATETIME = Utility.GetSysDateTime(); db.T_PARTNER_CATALOG_UNITS.Add(worker); db.SaveChanges(); } UploadImage(db, partnerEntity.userId, ImageType.Profile, partnerEntity.imageInfoList); return(true); }
public ActionResult UpdateFavourite(FavouriteEntity favouriteEntity) { IDbContextTransaction tran = _context.Database.BeginTransaction(); try { System.Web.Http.HttpError errorHttp = null; // Favouriteの場合 if (favouriteEntity.favouriteFlag == 1) { var query = from d in _context.D_FAVOURITES where d.USER_ID == favouriteEntity.userId && d.MODE_USER == (int)Mode.Hirer && d.FAVOURITE_USER_ID == favouriteEntity.favouriteUserId select d; if (!query.Any()) { D_FAVOURITE favoutire = new D_FAVOURITE(); favoutire.USER_ID = favouriteEntity.userId; favoutire.MODE_USER = (int)Mode.Hirer; favoutire.FAVOURITE_USER_ID = favouriteEntity.favouriteUserId; favoutire.CATALOG_CD = favouriteEntity.catalog.catalogCd.GetValueOrDefault(0); favoutire.REG_DATETIME = Utility.GetSysDateTime(); _context.D_FAVOURITES.Add(favoutire); _context.SaveChanges(); } } else { var query = from d in _context.D_FAVOURITES where d.USER_ID == favouriteEntity.userId && d.MODE_USER == (int)Mode.Hirer && d.FAVOURITE_USER_ID == favouriteEntity.favouriteUserId select d; if (query.Any()) { D_FAVOURITE favoutire = query.Single(); _context.D_FAVOURITES.Remove(favoutire); _context.SaveChanges(); } } // Commit transaction. tran.Commit(); errorHttp = new System.Web.Http.HttpError("Update is success!"); return(Ok(new Result { Status = 200, Message = errorHttp.Message, Data = true })); } catch (Exception ex) { // Rollback transaction. tran.Rollback(); System.Web.Http.HttpError error = new System.Web.Http.HttpError("Error system!"); return(Ok(new Result { Status = 404, Message = error.Message, Data = false })); } }
public bool DeleteUser(decimal id) { IDbContextTransaction tran = _context.Database.BeginTransaction(); try { var query = from d in _context.M_USERS where d.USER_ID == id select d; if (query.Any()) { M_USER user = query.Single(); _context.M_USERS.Add(user); _context.SaveChanges(); } // Remove image. if (!Utility.RemoveImage(_context, id, ImageType.Profile)) { return(false); } // Commit transaction. tran.Commit(); return(true); } catch { // Rollback transaction. tran.Rollback(); return(false); } }