public async Task <IActionResult> CreateAsync([FromBody] NoticeCreateDto noticeCreate)
        {
            var notice = _mapper.Map <Notice>(noticeCreate);

            var autenticated = await _identityService.GetAutenticatedPersonAsync(HttpContext.RequestAborted);

            notice
            .AddPostedBy(autenticated);

            _noticeRepository.Add(notice);

            await _noticeRepository.UnitOfWork.CommitAsync(HttpContext.RequestAborted);

            if (noticeCreate.SendNotification)
            {
                var data = new Dictionary <string, string>();
                data.Add("Notice", notice.Id.ToString());

                var image = $"https://guadalupestorage.blob.core.windows.net/assets/" + notice.Image;

                await _notificationService.SendByTopicAsync(notice.Title, notice.Message, image, "notices", data, HttpContext.RequestAborted)
                .ConfigureAwait(false);
            }

            return(Created($"api/notice/{notice.Id}", notice.Id));
        }
Exemplo n.º 2
0
 public string AddNotice(Notice ent)
 {
     try
     {
         NoticeRepository.Add(ent);
         unitOfWork.Commit();
     }
     catch (Exception ex)
     {
         return(ex.ToString());// "新增失败,请核对信息后再重试,或联系系统管理员。";
     }
     return("OK");
 }
Exemplo n.º 3
0
 public string AddNotice(Notice ent)
 {
     try
     {
         NoticeRepository.Add(ent);
         unitOfWork.Commit();
     }
     catch
     {
         return("新增失败,请核对信息后再重试,或联系系统管理员。");
     }
     return("OK");
 }
Exemplo n.º 4
0
        public bool CreateNotice(Notice notice)
        {
            bool isSuccess = true;

            try
            {
                noticeRepository.Add(notice);
                this.SaveRecord();
                ServiceUtil <Notice> .WriteActionLog(notice.Id, ENUMOperation.CREATE, notice);
            }
            catch (Exception ex)
            {
                isSuccess = false;
                logger.Error("Error in creating Notice", ex);
            }
            return(isSuccess);
        }
Exemplo n.º 5
0
        public ActionResult AddNotice(NoticeView notice, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                //if(image != null)
                //{
                //    noticeForSave.ImageData = new byte[image.ContentLength];
                //    noticeForSave.ImageMimeType = image.ContentType;
                //    image.InputStream.Read(notice.ImageData, 0, image.ContentLength);
                //}

                Mapper.Initialize(cfg => cfg.CreateMap <NoticeView, Notice>()
                                  .ForMember("DateCreation", opt => opt.UseValue(DateTime.Now)));
                Notice noticeForSave = Mapper.Map <NoticeView, Notice>(notice);

                if (image != null)
                {
                    noticeForSave.ImageData     = new byte[image.ContentLength];
                    noticeForSave.ImageMimeType = image.ContentType;
                    image.InputStream.Read(noticeForSave.ImageData, 0, image.ContentLength);
                }

                //noticeForSave = notice.Notice;
                //noticeForSave.AuthorName = notice.AuthorName;
                //noticeForSave.CategoryID = notice.CategoryID;
                //noticeForSave.CityId = notice.CityId;
                //noticeForSave.Content = notice.Content;
                //noticeForSave.Email = notice.Email;
                //noticeForSave.Phone = notice.Phone;
                //noticeForSave.Theme = notice.Theme;
                //noticeForSave.DateCreation = DateTime.Now;
                //noticeForSave.IsLost.
                repository.Add(noticeForSave);
                repository.SaveNotice();

                return(RedirectToAction("List"));
            }

            notice.Categories = repository.Categories.Select(p => new SelectListItem {
                Text = p.CategoryName, Value = p.CategoryID.ToString()
            });
            notice.Cities = repository.Cities.Select(p => new SelectListItem {
                Text = p.CityName, Value = p.CityId.ToString()
            });
            return(View(notice));
        }