public ActionResult AddNoticeToDatabase(NewNoticeViewModel model)
        {
            try
            {
                var newNoticeToAdd = new NoticeEntity();
                newNoticeToAdd.Amount        = decimal.Parse(model.Amount);
                newNoticeToAdd.CategoryId    = int.Parse(model.SelectedCategoryId);
                newNoticeToAdd.CreateDate    = DateTime.Now;
                newNoticeToAdd.Description   = model.Description;
                newNoticeToAdd.ExprireDate   = DateTime.Now.AddDays(int.Parse(model.ExpireTo));
                newNoticeToAdd.NoticePlaceId = int.Parse(model.NoticePlaceId);
                newNoticeToAdd.Title         = model.Title;
                newNoticeToAdd.UserProfileId = WebMatrix.WebData.WebSecurity.CurrentUserId;

                var noticeRepo = new NoticeRepository();
                noticeRepo.AddNewNotice(newNoticeToAdd);
                ViewBag.Message = "Dodano ogłoszenie.";
            }
            catch (Exception ex)
            {
                ViewBag.Message       = "Ups coś poszło nie tak.";
                ViewBag.ExtendMessage = ex.Message;
            }
            return(View());
        }
Exemplo n.º 2
0
 //    [HandlerAuthorize(PermissionMode.Enforce)]
 public ActionResult SaveForm(string keyValue, NoticeEntity entity)
 {
     entity.author      = OperatorProvider.Provider.Current().Account;
     entity.create_time = DateTime.Now;
     noticebll.SaveForm(keyValue, entity);
     return(Success("操作成功。"));
 }
Exemplo n.º 3
0
        /// <summary>
        /// 公告实体
        /// </summary>
        /// <param name="keyValue">主键值</param>
        /// <returns></returns>
        public NoticeEntity GetEntity(string keyValue)
        {
            NoticeEntity noticeEntity = service.GetEntity(keyValue);

            noticeEntity.NewsContent = WebHelper.HtmlDecode(noticeEntity.NewsContent);
            return(noticeEntity);
        }
Exemplo n.º 4
0
        public async Task <bool> UpdateAsync(long id, string code, string content, DateTime failureTime)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                NoticeEntity entity = await dbc.GetAll <NoticeEntity>().SingleOrDefaultAsync(g => g.Id == id);

                if (entity == null)
                {
                    return(false);
                }
                entity.Code        = code;
                entity.Content     = content;
                entity.FailureTime = failureTime;
                if (entity.FailureTime > DateTime.Now)
                {
                    entity.IsEnabled = true;
                }
                else
                {
                    entity.IsEnabled = false;
                }
                await dbc.SaveChangesAsync();

                return(true);
            }
        }
        public NoticeBasicResponse Basic([FromBody] NoticeBasicRequest request)
        {
            NoticeBasicResponse response = new NoticeBasicResponse();

            if (request == null)
            {
                response.Status = -1;
                return(response);
            }

            NoticeEntity entity = null;

            if (request.Id > 0)
            {
                entity = noticeRepository.GetEntityById(request.Id);
            }

            if (entity == null)
            {
                response.Status = 404;
                return(response);
            }

            response.Item = noticeConvertor.ToBasicVo(entity);

            response.Status = 1;
            return(response);
        }
        public NoticeUpdateResponse Update([FromBody] NoticeUpdateRequest request)
        {
            NoticeUpdateResponse response = new NoticeUpdateResponse();

            if (request == null)
            {
                response.Status = -1;
                return(response);
            }

            if (request.Id > 0)
            {
                NoticeEntity entity = noticeRepository.GetEntityById(request.Id);
                if (entity != null)
                {
                    noticeRepository.UpdateById(noticeConvertor.ToEntity(request, entity));
                    response.Status = 1;
                }
            }

            if (response.Status == 0)
            {
                response.Status = 404;
                return(response);
            }

            response.Status = 1;
            return(response);
        }
Exemplo n.º 7
0
        public async Task <long> AddAsync(string code, string content, DateTime failureTime, long creatorId)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                NoticeEntity entity = new NoticeEntity();
                entity.Code    = code;
                entity.Content = content;
                entity.Url     = "";
                entity.Creator = await dbc.GetParameterAsync <AdminEntity>(a => a.Id == creatorId, a => a.Mobile);

                entity.FailureTime = failureTime;
                if (entity.FailureTime > DateTime.Now)
                {
                    entity.IsEnabled = true;
                }
                else
                {
                    entity.IsEnabled = false;
                }
                dbc.Notices.Add(entity);
                await dbc.SaveChangesAsync();

                return(entity.Id);
            }
        }
Exemplo n.º 8
0
        public JsonResult GetMyNotice()
        {
            var result = new ReturnMessage(false)
            {
                Message = "获取失败!"
            };

            try
            {
                NoticeEntity para = new NoticeEntity();
                para.CustermerId = LoginUser.UserId;
                para.sidx        = "Createtime";
                para.sord        = "desc";
                var list = NoticeBLL.Instance.GetList(para);

                result.IsSuccess          = true;
                result.Message            = "获取成功";
                result.ResultData["List"] = list;
            }
            catch (Exception ex)
            {
                ex.Data["Method"] = "NoticeController>>GetMyNotice";
                new ExceptionHelper().LogException(ex);
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 9
0
        public void ModifyNotice(NoticeInfo noticeInfo)
        {
            try
            {
                using (ILHDBTran tran = BeginTran())
                {
                    NoticeManager manager = new NoticeManager(tran);

                    NoticeEntity entity = manager.GetNotice(noticeInfo.Id);
                    if (entity == null)
                    {
                        throw new ArgumentNullException("通知数据不存在!!");
                    }
                    entity.Name        = noticeInfo.Name;
                    entity.Title       = noticeInfo.Title;
                    entity.IsHasDetail = noticeInfo.IsHasDetail;
                    entity.Message     = noticeInfo.Message;
                    entity.IsForeRed   = noticeInfo.IsForeRed;
                    entity.IsForeBold  = noticeInfo.IsForeBold;
                    entity.StartTime   = noticeInfo.StartTime;
                    entity.EndTime     = noticeInfo.EndTime;
                    entity.IsEnd       = noticeInfo.IsEnd;
                    manager.ModifyNotice(entity);
                    tran.Commit();
                }
            }
            catch (Exception ex)
            {
                throw HandleException("Notice", "Modify", ex);
            }
        }
Exemplo n.º 10
0
        public CommunicationObject AddNotify(string xml)
        {
            try
            {
                CommunicationObject notifyInfo   = XmlAnalyzer.AnalyseXmlToCommunicationObject <CommunicationObject>(xml);
                NoticeEntity        noticeEntity = new NoticeEntity();
                noticeEntity.NoticeId      = notifyInfo.Id;
                noticeEntity.NoticeVersion = notifyInfo.Version;
                noticeEntity.MessengerId   = notifyInfo.MessengerId;
                noticeEntity.Timestamp     = notifyInfo.Timestamp;
                noticeEntity.TranType      = (int)notifyInfo.TransactionType;
                noticeEntity.Digest        = notifyInfo.Digest;
                noticeEntity.ResponseText  = xml;
                noticeEntity.NotifyTime    = DateTime.Now;
                noticeEntity.XmlHeader     = notifyInfo.XmlHeader;
                NoticeManager noticeManager = new NoticeManager(DbAccess);
                noticeManager.AddNotice(noticeEntity);

                return(notifyInfo);
            }
            catch (Exception ex)
            {
                string errMsg = "添加通知XML到数据库失败!" + xml;
                throw HandleException(LogCategory.Notice, errMsg, ex);
            }
        }
Exemplo n.º 11
0
        public async Task <BaseResult <bool> > Disable(string notice_id, string disable_desc, int type)
        {
            if (string.IsNullOrEmpty(notice_id))
            {
                return(new BaseResult <bool>(808));
            }

            //首先查询数据读取原始的desc
            var          str          = "";
            NoticeEntity noticeEntity = await noticeRepository.GetAsync(c => c.notice_id.Equals(notice_id));

            if (string.IsNullOrEmpty(noticeEntity.disabledesc))
            {
                str = "{'disable':'" + noticeEntity.disable + "','disable_desc':'" + disable_desc + "'}";
            }
            else
            {
                str = noticeEntity.disabledesc + ",{'disable':'" + noticeEntity.disable + "','disable_desc':'" + disable_desc + "'}";
            }
            NoticeEntity notice = new NoticeEntity()
            {
                notice_id   = notice_id,
                disabledesc = str,
                disable     = type
            };

            var isTrue = await noticeRepository.UpdateAsync(notice, true, true, c => c.disable, c => c.disabledesc);

            if (!isTrue)
            {
                return(new BaseResult <bool>(201, false));
            }
            return(new BaseResult <bool>(200, true));
        }
Exemplo n.º 12
0
    public async Task <ApiError> InsertAsync(NoticeModel model)
    {
        var checkresult = await ValidateModelAsync(model);

        if (!checkresult.Successful)
        {
            return(checkresult);
        }
        NoticeEntity entity = model !;

        try
        {
            var result = await _noticeRepository.InsertAsync(entity);

            if (result.Successful)
            {
                model.Id = entity.Id;
            }
            return(ApiError.FromDalResult(result));
        }
        catch (Exception ex)
        {
            return(ApiError.FromException(ex));
        }
    }
Exemplo n.º 13
0
 public void AddNewNotice(NoticeEntity notice)
 {
     using (var context = new UsersContext())
     {
         context.Notices.Add(notice);
         context.SaveChanges();
     }
 }
Exemplo n.º 14
0
 /// <summary>
 /// 将entity转换为vo。不包括来自元数据的属性
 /// </summary>
 private void CopyToVo(NoticeVo vo, NoticeEntity entity)
 {
     vo.Id             = entity.Id;
     vo.Title          = entity.Title;
     vo.Body           = entity.Body;
     vo.DataStatus     = entity.DataStatus;
     vo.CreateTime     = entity.CreateTime;
     vo.LastUpdateTime = entity.LastUpdateTime;
 }
Exemplo n.º 15
0
        /// <summary>
        /// 将entity转换为vo
        /// </summary>
        public NoticeBasicVo ToBasicVo(NoticeEntity entity)
        {
            NoticeBasicVo vo = new NoticeBasicVo();

            CopyToVo(vo, entity);

            vo.Category = entity.Category;

            return(vo);
        }
Exemplo n.º 16
0
        public async Task <IActionResult> Add(NoticeEntity noticeEntity)
        {
            if (ModelState.IsValid)
            {
                var data = await noticeService.Add(noticeEntity);

                return(Json(data));
            }
            return(Json(ParrNoPass()));
        }
Exemplo n.º 17
0
 /// <summary>
 /// 保存表单(新增、修改)
 /// </summary>
 /// <param name="keyValue">主键值</param>
 /// <param name="entity">实体对象</param>
 /// <returns></returns>
 public void SaveForm(string keyValue, NoticeEntity entity)
 {
     try
     {
         service.SaveForm(keyValue, entity);
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 18
0
        /// <summary>
        /// 将entity转换为vo
        /// </summary>
        public NoticeExtendedVo ToExtendedVo(NoticeEntity entity)
        {
            NoticeExtendedVo vo = new NoticeExtendedVo();

            CopyToVo(vo, entity);
            if (!string.IsNullOrEmpty(entity.Category))
            {
                vo.Category = metaNoticeCategoryProvider.ToMetadata(entity.Category);
            }

            return(vo);
        }
Exemplo n.º 19
0
 /// <summary>
 /// 保存公告表单(新增、修改)
 /// </summary>
 /// <param name="keyValue">主键值</param>
 /// <param name="newsEntity">公告实体</param>
 /// <returns></returns>
 public void SaveForm(string keyValue, NoticeEntity newsEntity)
 {
     try
     {
         newsEntity.NewsContent = WebHelper.HtmlEncode(newsEntity.NewsContent);
         service.SaveForm(keyValue, newsEntity);
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 20
0
 public void SubmitForm(NoticeEntity entity, string keyValue)
 {
     if (!string.IsNullOrEmpty(keyValue))
     {
         entity.Modify(keyValue);
         service.Update(entity);
     }
     else
     {
         entity.Create();
         service.Insert(entity);
     }
 }
Exemplo n.º 21
0
        public async Task <NoticeDTO> GetModelAsync(long id)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                NoticeEntity entity = await dbc.GetAll <NoticeEntity>().AsNoTracking().SingleOrDefaultAsync(g => g.Id == id);

                if (entity == null)
                {
                    return(null);
                }
                return(ToDTO(entity));
            }
        }
Exemplo n.º 22
0
 public void UpdateNotice(NoticeEntity noticeToUpdate)
 {
     using (var context = new UsersContext())
     {
         var notice = context.Notices.FirstOrDefault(x => x.Id == noticeToUpdate.Id);
         notice.Amount        = noticeToUpdate.Amount;
         notice.CategoryId    = noticeToUpdate.CategoryId;
         notice.Description   = noticeToUpdate.Description;
         notice.NoticePlaceId = noticeToUpdate.NoticePlaceId;
         notice.Title         = noticeToUpdate.Title;
         context.SaveChanges();
     }
 }
Exemplo n.º 23
0
        public async Task <ActionResult> SubmitForm(NoticeEntity noticeEntity, string keyValue)
        {
            try
            {
                await _service.SubmitForm(noticeEntity, keyValue);

                return(await Success("操作成功。", "", keyValue));
            }
            catch (Exception ex)
            {
                return(await Error(ex.Message, "", keyValue));
            }
        }
Exemplo n.º 24
0
        private NoticeDTO ToDTO(NoticeEntity entity)
        {
            NoticeDTO dto = new NoticeDTO();

            dto.CreateTime  = entity.CreateTime;
            dto.Id          = entity.Id;
            dto.Code        = entity.Code;
            dto.Content     = entity.Content;
            dto.FailureTime = entity.FailureTime;
            dto.IsEnabled   = entity.IsEnabled;
            dto.Url         = entity.Url;
            return(dto);
        }
Exemplo n.º 25
0
        /// <summary>
        /// 插入消息
        /// </summary>
        /// <param name="customerid"></param>
        /// <param name="customername"></param>
        /// <param name="articleId"></param>
        /// <param name="title"></param>
        /// <param name="type"></param>
        void InsertNotice(string customerid, string customername, string articleId, string title, int?type)
        {
            NoticeEntity noticeentity = new NoticeEntity();

            noticeentity.NoticeId      = Util.Util.NewUpperGuid();
            noticeentity.CustermerId   = customerid;
            noticeentity.CustermerName = customername;
            noticeentity.CustermerType = type;
            noticeentity.ArticleId     = articleId;
            noticeentity.ArticleName   = title;
            noticeentity.Createtime    = DateTime.Now;
            noticeentity.CreateId      = LoginUser.UserId;
            NoticeBLL.Instance.Add(noticeentity);
        }
Exemplo n.º 26
0
        public NoticeDTO ToDTO(NoticeEntity entity)
        {
            NoticeDTO dto = new NoticeDTO();

            dto.CreateTime  = entity.CreateTime;
            dto.Enabled     = entity.Enabled;
            dto.Content     = entity.Content;
            dto.Creator     = entity.Creator;
            dto.FailureTime = entity.FailureTime;
            dto.Id          = entity.Id;
            dto.Tip         = entity.Tip;
            dto.Title       = entity.Title;
            dto.Url         = entity.Url;
            return(dto);
        }
Exemplo n.º 27
0
        public NoticeEntity ToEntity(NoticeCreateRequest request)
        {
            NoticeEntity entity = new NoticeEntity();

            var item = request.Item;

            entity.Title          = item.Title;
            entity.Body           = item.Body;
            entity.Category       = item.Category;
            entity.DataStatus     = 1;
            entity.CreateTime     = TimeConvertor.FromMilliTicks(TimeConvertor.ToMilliTicks(DateTime.Now));
            entity.LastUpdateTime = TimeConvertor.FromMilliTicks(TimeConvertor.ToMilliTicks(DateTime.Now));

            return(entity);
        }
Exemplo n.º 28
0
        public async Task <bool> DeleteAsync(long id)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                NoticeEntity entity = await dbc.GetAll <NoticeEntity>().SingleOrDefaultAsync(g => g.Id == id);

                if (entity == null)
                {
                    return(false);
                }
                entity.IsDeleted = true;
                await dbc.SaveChangesAsync();

                return(true);
            }
        }
Exemplo n.º 29
0
        public async Task <bool> FrozenAsync(long id)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                NoticeEntity entity = await dbc.GetAll <NoticeEntity>().SingleOrDefaultAsync(p => p.Id == id);

                if (entity == null)
                {
                    return(false);
                }
                entity.Enabled = 0;
                await dbc.SaveChangesAsync();

                return(true);
            }
        }
Exemplo n.º 30
0
        public async Task <long> AddAsync(string title, string content, int enabled, long adminId)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                NoticeEntity entity = new NoticeEntity();
                entity.Title   = title;
                entity.Content = content;
                entity.Enabled = enabled;
                entity.Creator = await dbc.GetStringPropertyAsync <AdminEntity>(a => a.Id == adminId, a => a.Name);

                dbc.Notices.Add(entity);
                await dbc.SaveChangesAsync();

                return(entity.Id);
            }
        }