Beispiel #1
0
        public List <EventJsonModel> Get([FromUri] EventDataGet eventdata)
        {
            long unixTimeStart = eventdata.periodstart;
            long unixTimeEnd   = eventdata.periodend;

            DateTime TimeStart = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
            long     unixTimeStampInTicksStart = unixTimeStart * TimeSpan.TicksPerMillisecond;
            DateTime periodStart = new DateTime(TimeStart.Ticks + unixTimeStampInTicksStart, System.DateTimeKind.Utc);

            DateTime TimeEnd = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
            long     unixTimeStampInTicksEnd = unixTimeEnd * TimeSpan.TicksPerMillisecond;
            DateTime periodEnd = new DateTime(TimeStart.Ticks + unixTimeStampInTicksEnd, System.DateTimeKind.Utc);

            int enterpriseid = eventdata.enterpriseid;
            int productionid = eventdata.productionid;

            List <Event> eventslist = _eventsRepository.GetAll().ToList();

            List <Event> eventslistPeriod2;

            if (productionid == -1)
            {
                eventslistPeriod2 = (from eve in eventslist
                                     where eve.StartDate >= periodStart  // && eve.EndDate  <= periodEnd
                                     where  eve.LocationId == enterpriseid
                                     select eve).ToList();
            }
            else
            {
                eventslistPeriod2 = (from eve in eventslist
                                     where eve.StartDate >= periodStart   //&& eve.EndDate <= periodEnd
                                     where eve.LocationId == enterpriseid //&& eve.ProductionId == productionid
                                     select eve).ToList();
            }

            List <EventJsonModel> eventmodel = new List <EventJsonModel>();

            foreach (Event entity in eventslistPeriod2)
            {
                long unixTimeStartVM = (long)(entity.StartDate - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;
                long unixTimeEndVM   = (long)(entity.EndDate - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;

                EventJsonModel model = new EventJsonModel();
                model.Id          = entity.Id;
                model.Name        = entity.Name;
                model.StartDate   = unixTimeStartVM;
                model.EndDate     = unixTimeEndVM;
                model.EventTypeId = entity.EventTypeId;
                model.Fio         = entity.Fio;
                model.Color       = entity.Color;
                eventmodel.Add(model);
            }

            return(eventmodel);
        }
        public void Configure()
        {
            Mapper.AddMap <Event, EventJsonModel>((source) =>
            {
                var result = new EventJsonModel();
                result.InjectFrom(source);
                long unixTimeStart = (long)(source.StartDate - new DateTime(1970, 1, 1)).TotalMilliseconds;
                long unixTimeEnd   = (long)(source.EndDate - new DateTime(1970, 1, 1)).TotalMilliseconds;
                result.StartDate   = unixTimeStart;
                result.EndDate     = unixTimeEnd;

                return(result);
            });



            Mapper.AddMap <EventJsonModel, Event>((source) =>
            {
                var result = new Event();
                return(result);
            });
        }