示例#1
0
 /// <summary>
 /// Get item
 /// </summary>
 /// <param name="model"></param>
 /// <returns>FanpageModel. Throw exception if not found or get some error</returns>
 public string GetTokenByItem(FanpageModel model)
 {
     try
     {
         using (var context = new TDHEntities())
         {
             FB_FANPAGE _md = context.FB_FANPAGE.FirstOrDefault(m => m.uid == model.UID && m.created_by == model.CreateBy && !m.deleted);
             if (_md == null)
             {
                 throw new DataAccessException(FILE_NAME, "GetTokenByItem", model.CreateBy);
             }
             if (_md.expires_on <= DateTime.Now || _md.start_on >= DateTime.Now)
             {
                 return("");
             }
             return(_md.auth_token);
         }
     }
     catch (DataAccessException fieldEx)
     {
         throw fieldEx;
     }
     catch (Exception ex)
     {
         throw new ServiceException(FILE_NAME, "GetTokenByItem", model.CreateBy, ex);
     }
 }
示例#2
0
 /// <summary>
 /// Get item
 /// </summary>
 /// <param name="model"></param>
 /// <returns>FanpageModel. Throw exception if not found or get some error</returns>
 public FanpageModel GetItemByID(FanpageModel model)
 {
     try
     {
         using (var context = new TDHEntities())
         {
             FB_FANPAGE _md = context.FB_FANPAGE.FirstOrDefault(m => m.uid == model.UID && m.created_by == model.CreateBy && !m.deleted);
             if (_md == null)
             {
                 throw new DataAccessException(FILE_NAME, "GetItemByID", model.CreateBy);
             }
             return(new FanpageModel()
             {
                 UID = _md.uid,
                 UserName = _md.user_name,
                 Link = _md.link,
                 DisplayName = _md.display_name
             });
         }
     }
     catch (DataAccessException fieldEx)
     {
         throw fieldEx;
     }
     catch (Exception ex)
     {
         throw new ServiceException(FILE_NAME, "GetItemByID", model.CreateBy, ex);
     }
 }
示例#3
0
 /// <summary>
 /// Delete
 /// </summary>
 /// <param name="model"></param>
 /// <returns>ResponseStatusCodeHelper</returns>
 public ResponseStatusCodeHelper Delete(FanpageModel model)
 {
     try
     {
         using (var context = new TDHEntities())
         {
             FB_FANPAGE _md = context.FB_FANPAGE.FirstOrDefault(m => m.uid == model.UID && m.created_by == model.CreateBy && !m.deleted);
             if (_md == null)
             {
                 throw new DataAccessException(FILE_NAME, "Delete", model.CreateBy);
             }
             context.FB_FANPAGE.Remove(_md);
             context.Entry(_md).State = EntityState.Deleted;
             context.SaveChanges();
         }
     }
     catch (DataAccessException fieldEx)
     {
         throw fieldEx;
     }
     catch (Exception ex)
     {
         throw new ServiceException(FILE_NAME, "Delete", model.CreateBy, ex);
     }
     Notifier.Notification(model.CreateBy, Message.DeleteSuccess, Notifier.TYPE.Success);
     return(ResponseStatusCodeHelper.Success);
 }
示例#4
0
 /// <summary>
 /// Save
 /// </summary>
 /// <param name="model"></param>
 /// <returns>ResponseStatusCodeHelper</returns>
 public ResponseStatusCodeHelper Save(FanpageModel model)
 {
     try
     {
         using (var context = new TDHEntities())
         {
             model.Insert = false;
             FB_FANPAGE _md = new FB_FANPAGE();
             _md = context.FB_FANPAGE.FirstOrDefault(m => m.uid == model.UID && !m.deleted && m.created_by == model.CreateBy);
             if (_md == null)
             {
                 _md          = new FB_FANPAGE();
                 _md.uid      = model.UID;
                 model.Insert = true;
             }
             _md.link         = model.Link;
             _md.user_name    = model.UserName;
             _md.display_name = model.DisplayName;
             _md.phone        = model.Phone;
             _md.email        = model.Email;
             _md.website      = model.Website;
             _md.auth_token   = model.AuthToken;
             _md.start_on     = model.StartOn;
             _md.last_execute = model.LastExecute;
             _md.expires_on   = model.ExpiresOn;
             _md.ordering     = model.Ordering;
             if (model.Insert)
             {
                 _md.created_by   = model.CreateBy;
                 _md.created_date = DateTime.Now;
                 context.FB_FANPAGE.Add(_md);
                 context.Entry(_md).State = EntityState.Added;
             }
             else
             {
                 _md.updated_by   = model.UpdateBy;
                 _md.updated_date = DateTime.Now;
                 context.FB_FANPAGE.Attach(_md);
                 context.Entry(_md).State = EntityState.Modified;
             }
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw new ServiceException(FILE_NAME, "Save", model.CreateBy, ex);
     }
     if (model.Insert)
     {
         Notifier.Notification(model.CreateBy, Message.InsertSuccess, Notifier.TYPE.Success);
     }
     else
     {
         Notifier.Notification(model.CreateBy, Message.UpdateSuccess, Notifier.TYPE.Success);
     }
     return(ResponseStatusCodeHelper.Success);
 }
示例#5
0
 /// <summary>
 /// Update Token
 /// </summary>
 /// <param name="model"></param>
 /// <returns>ResponseStatusCodeHelper</returns>
 public ResponseStatusCodeHelper UpdateToken(FanpageModel model)
 {
     try
     {
         using (var context = new TDHEntities())
         {
             FB_FANPAGE _md = context.FB_FANPAGE.FirstOrDefault(m => m.uid == model.UID && !m.deleted && m.created_by == model.CreateBy);
             if (_md == null)
             {
                 throw new DataAccessException(FILE_NAME, "UpdateToken", model.CreateBy);
             }
             _md.auth_token   = model.AuthToken;
             _md.start_on     = model.StartOn;
             _md.last_execute = model.LastExecute;
             _md.expires_on   = model.ExpiresOn;
             _md.updated_by   = model.UpdateBy;
             _md.updated_date = DateTime.Now;
             context.FB_FANPAGE.Attach(_md);
             context.Entry(_md).State = EntityState.Modified;
             context.SaveChanges();
         }
     }
     catch (DataAccessException fieldEx)
     {
         throw fieldEx;
     }
     catch (Exception ex)
     {
         throw new ServiceException(FILE_NAME, "UpdateToken", model.CreateBy, ex);
     }
     if (model.Insert)
     {
         Notifier.Notification(model.CreateBy, Message.InsertSuccess, Notifier.TYPE.Success);
     }
     else
     {
         Notifier.Notification(model.CreateBy, Message.UpdateSuccess, Notifier.TYPE.Success);
     }
     return(ResponseStatusCodeHelper.Success);
 }
示例#6
0
        public ActionResult DeleteFanpage(FanpageModel model)
        {
            try
            {
                #region " [ Declaration ] "

                FanpageService _service = new FanpageService();

                #endregion

                #region " [ Main processing ] "

                model.Publish    = true;
                model.CreateBy   = UserID;
                model.UpdateBy   = UserID;
                model.CreateDate = DateTime.Now;
                model.UpdateDate = DateTime.Now;

                #endregion

                // Call to service
                return(this.Json(_service.Delete(model), JsonRequestBehavior.AllowGet));
            }
            catch (ServiceException serviceEx)
            {
                throw serviceEx;
            }
            catch (DataAccessException accessEx)
            {
                throw accessEx;
            }
            catch (Exception ex)
            {
                throw new ControllerException(FILE_NAME, "DeleteFanpage", UserID, ex);
            }
        }