示例#1
0
        public ActionResult GetSystemMessage([FromRoute] decimal id)
        {
            var query = from d in _context.D_NOTIFYS
                        where d.NOTIFY_ID == id
                        select d;

            if (!query.Any())
            {
                return(Ok(new Result
                {
                    Status = 200,
                    Message = string.Empty,
                    Data = string.Empty
                }));
            }

            D_NOTIFY notify = query.Single();

            NotifyEntity entity = new NotifyEntity();

            entity.notifyId        = notify.NOTIFY_ID;
            entity.notifyType      = notify.NOTIFY_TYPE;
            entity.objectId        = notify.OBJECT_ID;
            entity.notifyDate      = notify.NOTIFY_DATE;
            entity.userSendId      = notify.USER_SEND_ID;
            entity.userReceiveId   = notify.USER_RECIEVE_ID;
            entity.receiveModeUser = notify.RECEIVE_MODE_USER;
            entity.content         = notify.CONTENT;

            if (entity.notifyType == (int)NotifyType.System)
            {
                var user = from d in _context.M_USERS
                           where d.USER_ID == notify.USER_RECIEVE_ID
                           select d;

                M_USER userM = user.Single();

                var message = from d in _context.M_SYSTEM_MESSAGES
                              where d.MESSAGE_CD == entity.objectId &&
                              d.LANGUAGE_TYPE == userM.LANGUAGE_TYPE
                              select d;

                if (message.Any())
                {
                    entity.content = message.SingleOrDefault().MESSAGE_CONTENT;
                }
            }

            return(Ok(new Result
            {
                Status = 200,
                Message = string.Empty,
                Data = entity.content
            }));
        }
示例#2
0
        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
                }));
            }
        }
示例#3
0
        /// <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);
        }
示例#4
0
        public ActionResult GetNotifyById([FromRoute] decimal id)
        {
            var query = from d in _context.D_NOTIFYS
                        where d.NOTIFY_ID == id
                        select d;

            if (!query.Any())
            {
                return(Ok(new Result
                {
                    Status = 404,
                    Message = string.Empty,
                    Data = false
                }));
            }

            D_NOTIFY notify = query.Single();

            NotifyEntity entity = new NotifyEntity();

            entity.notifyId        = notify.NOTIFY_ID;
            entity.notifyType      = notify.NOTIFY_TYPE;
            entity.objectId        = notify.OBJECT_ID;
            entity.notifyDate      = notify.NOTIFY_DATE;
            entity.userSendId      = notify.USER_SEND_ID;
            entity.userReceiveId   = notify.USER_RECIEVE_ID;
            entity.receiveModeUser = notify.RECEIVE_MODE_USER;
            entity.content         = notify.CONTENT;

            var user = from d in _context.M_USERS
                       where d.USER_ID == notify.USER_RECIEVE_ID
                       select d;

            if (!user.Any())
            {
                return(Ok(new Result
                {
                    Status = 404,
                    Message = string.Empty,
                    Data = false
                }));
            }

            string languageType = user.Single().LANGUAGE_TYPE;

            if (notify.NOTIFY_TYPE == (int)NotifyType.Estimation)
            {
                entity.content = string.Format(Utility.GetMessageInfo(_context, languageType, notify.NOTIFY_TYPE).messageContent, notify.CONTENT);
            }
            else if (notify.NOTIFY_TYPE == (int)NotifyType.Job)
            {
                string status = string.Empty;

                var queryHistory = from d in _context.D_HISTORYS
                                   join m in _context.M_NAMES on d.STATUS equals m.CD
                                   where d.EXCHANGE_ID == notify.OBJECT_ID &&
                                   m.TYPE_NAME == "HISTORY_STATUS"
                                   select m;

                if (queryHistory.Any())
                {
                    if (string.IsNullOrEmpty(languageType) || languageType.Equals(Constant.LANGUAGE_VN))
                    {
                        status = queryHistory.Single().NAME;
                    }
                    else
                    {
                        status = queryHistory.Single().NAME_EN;
                    }

                    entity.content = string.Format(Utility.GetMessageInfo(_context, languageType, notify.NOTIFY_TYPE).messageContent, notify.CONTENT, status);
                }
            }
            else
            {
                entity.content = string.Format(Utility.GetSystemMessageInfo(_context, languageType, notify.OBJECT_ID).message);
            }

            return(Ok(new Result
            {
                Status = 200,
                Message = string.Empty,
                Data = entity
            }));
        }