Example #1
0
        public CrResult <EventDto> CreateEvent(long userId, EventCrDto ev)
        {
            var res = new CrResult <EventDto>();

            CheckEvent(ev, res);
            if (res.ActionResult == ActionResult.Success)
            {
                if (new UserRolesManager().CheckPermition(userId, ev.ChannelId, _addNewsPermitionId))
                {
                    try
                    {
                        var createdEv = _context.Event.Add(Converter.ConvertToEvent(ev));
                        _context.SaveChanges();
                        res.CreatedObject = Converter.ConvertToEventDto(createdEv);
                    }
                    catch (Exception)
                    {
                        res.ActionResult = ActionResult.DatabaseError;
                    }
                }
                else
                {
                    res.ActionResult = ActionResult.PermissionDenied;
                }
            }
            return(res);
        }
Example #2
0
 public bool CreateEvent(long userId, EventCrDto ev)
 {
     if (CheckPermition(userId, ev.ChannelId, "Add news"))
     {
         try
         {
             _context.Event.Add(new Event
             {
                 channel_id    = ev.ChannelId,
                 improtance_id = ev.ImportanceId,
                 creation_time = DateTime.Now,
                 description   = ev.Description,
                 title         = ev.Title,
                 event_time    = ev.EventTime
             });
             _context.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             throw;
         }
     }
     return(false);
 }
Example #3
0
 public EventCreationViewModel(long channelId, ObservableCollection <ImportanceDto> importanceScale, SchedulerClient client)
 {
     _client          = client;
     _importanceScale = importanceScale;
     _errors          = new EventErrors();
     _event           = new EventCrDto();
     _event.EventTime = DateTime.Now;
     _event.ChannelId = channelId;
 }
Example #4
0
 public List <EventDto> GetEvents(long userId, int count, int offset, DateTime dateTime, long channelId)
 {
     if (CheckPermition(userId, channelId, "Edit news"))
     {
         var events =
             _context.Event.Where(t => SqlFunctions.DateDiff("day", t.event_time, dateTime) < 0)
             .OrderByDescending(t => SqlFunctions.DateDiff("day", t.event_time, dateTime))
             .Take(count);
         return(EventCrDto.ConvertList(events.ToList()));
     }
     else
     {
         return(null);
     }
 }
Example #5
0
        public void CheckEvent(EventCrDto ev, Result res)
        {
            var checkStatus = Helper.CheckParam(ev.Description, _descriptionLenght, _descriptionNullAllowed);

            if (checkStatus != CheckStatus.Success)
            {
                res.AddError(new Error(checkStatus, nameof(ev.Description)));
            }
            checkStatus = Helper.CheckParam(ev.Title, _titleLenght, _titleNullAllowed);
            if (checkStatus != CheckStatus.Success)
            {
                res.AddError(new Error(checkStatus, nameof(ev.Title)));
            }
            if (ev.EventTime == DateTime.MinValue)
            {
                res.AddError(new Error(CheckStatus.ArgumentIsNull, nameof(ev.EventTime)));
            }
            if (ev.ImportanceId != null && !IsImportanceExist(ev.ImportanceId))
            {
                res.AddError(new Error(CheckStatus.IdDoesNotExist, nameof(ev.ImportanceId)));
            }
        }