Ejemplo n.º 1
0
        public BaseResponse <Notice> AddNotice(Notice model)
        {
            var response = new BaseResponse <Notice>();
            var errors   = Validate <Notice>(model, new NoticeValidator());

            if (errors.Count() > 0)
            {
                BaseResponse <Notice> errResponse = new BaseResponse <Notice>(model, errors);
                errResponse.IsSuccess = false;
                return(errResponse);
            }
            try
            {
                model.CreatedOn = DateTime.Now;
                response.Value  = _noticeRepository.Add(model);
                try
                {
                    _applicationLoggingRepository.Log("EVENT", "CREATE", "Notice", response.Value.Id.ToString(), "", "", model, "", System.Web.HttpContext.Current.Request.UserHostAddress, model.CreatedBy);
                }
                catch
                { }
            }
            catch (Exception ex)

            {
                response.IsSuccess = false;
                response.Message   = "Error: " + ex.Message + " StackTrace: " + ex.StackTrace;
            }
            return(response);
        }
Ejemplo n.º 2
0
        public async Task Execute()
        {
            var notices = await parser.GetNotices();

            //берем самую старую запись, но не старше суток
            var n = notices.Where(x => x.Date > DateTime.Now.AddDays(-1))
                    .OrderBy(x => x.Date)
                    .FirstOrDefault();

            if (n != null)
            {
                n.Categories = categorizer.Categorize(n.FullText);
                var coordinates = await geocoding.GetCoordinatesAsync(n.FullText.RemovePunctuation());


                if ((coordinates?.Results?.Any()).HasValue)
                {
                    n.Latitude = coordinates.Results.FirstOrDefault() != null?coordinates.Results.FirstOrDefault().Geometry.Location.Latitude : 0;

                    n.Longitude = coordinates.Results.FirstOrDefault() != null?coordinates.Results.FirstOrDefault().Geometry.Location.Longitude : 0;
                }

                n.IsShown = true;
                Logger.Information("Add notice {@n}", n);
                noticeRepository.Add(n);

                // отправляем сообщение
                await SendNoticeAsync(n);
            }
        }
Ejemplo n.º 3
0
        public ActionResult AddNotice(notice re)
        {
            notice updatenotice          = null;
            HumanResourceContext context = new HumanResourceContext();

            if (re.ID == 0)
            {
                updatenotice = notrepo.Add(re);
            }
            else
            {
                updatenotice = notrepo.Update(re);
            }
            return(RedirectToAction("NoticeBoard", "HumanResource"));
        }