public async Task <bool> SavePreference(DtoSchedule schedule)
 {
     try
     {
         using (var data = Context)
         {
             var s = await(from item in data.Preferences where schedule.Id == item.id select item).FirstOrDefaultAsync();
             // Updating Course
             if (s != null)
             {
                 s.userId     = schedule.User.Id;
                 s.courseId   = schedule.Course.Id;
                 s.scheduleId = schedule.Id;
             }
             // Adding new Course
             else
             {
                 data.Preferences.Add(ScheduleConverter.DtoToDataAccess(schedule));
             }
             await data.SaveChangesAsync();
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Esempio n. 2
0
        public void UpdateSchedule(DtoSchedule schedule)
        {
            repository.UpdateEntity(schedule);
            UpdateDtoEntitiesList(schedules);

            SendServiceInfo($"Changed schedule {schedule.Id}");
        }
Esempio n. 3
0
        public ReportTask(ILogic logic, ILifetimeScope autofac, IRepository repository, IMonik monik, int id,
                          string name, string parameters, string dependsOn, DtoSchedule schedule, List <DtoOperation> opers)
        {
            this.monik      = monik;
            this.repository = repository;
            Id         = id;
            Name       = name;
            Schedule   = schedule;
            Operations = new List <IOperation>();

            Parameters = new Dictionary <string, object>();
            if (!string.IsNullOrEmpty(parameters))
            {
                Parameters = JsonConvert
                             .DeserializeObject <Dictionary <string, object> >(parameters);
            }

            DependsOn = new List <TaskDependency>();
            if (!string.IsNullOrEmpty(dependsOn))
            {
                DependsOn = JsonConvert
                            .DeserializeObject <List <TaskDependency> >(dependsOn);
            }

            this.autofac = autofac;

            ParseDtoOperations(logic, opers);
        } //ctor
Esempio n. 4
0
        public ContentResult UpdateSchedule(int id, [FromBody] DtoSchedule schedule)
        {
            try
            {
                if (id != schedule.Id)
                {
                    return new ContentResult
                           {
                               Content    = "Request id does not match schedule id",
                               StatusCode = StatusCodes.Status400BadRequest
                           }
                }
                ;

                logic.UpdateSchedule(schedule);

                return(new ContentResult {
                    StatusCode = StatusCodes.Status200OK
                });
            }
            catch
            {
                return(GetInternalErrorResult());
            }
        }
Esempio n. 5
0
        public int CreateSchedule(DtoSchedule schedule)
        {
            var newScheduleId = repository.CreateEntity(schedule);

            UpdateDtoEntitiesList(schedules);
            SendServiceInfo($"Created schedule {newScheduleId}");
            return(newScheduleId);
        }
 public static Preferences DtoToDataAccess(DtoSchedule d)
 {
     return(new Preferences
     {
         id = d.Id,
         courseId = d.Course.Id,
         scheduleId = d.ScheduleId,
         userId = d.User.Id
     });
 }
Esempio n. 7
0
        public ReportTask(ILogic logic, ILifetimeScope autofac, IRepository repository,
                          IMonik monik, int id,
                          string name, string parameters, DtoSchedule schedule, List <DtoOperation> opers)
        {
            this.monik      = monik;
            this.repository = repository;
            Id         = id;
            Name       = name;
            Schedule   = schedule;
            Operations = new List <IOperation>();

            Parameters = new Dictionary <string, object>();
            if (!string.IsNullOrEmpty(parameters))
            {
                Parameters = JsonConvert
                             .DeserializeObject <Dictionary <string, object> >(parameters);
            }

            foreach (var operation in opers)
            {
                IOperation newOper;

                var operType = operation.ImplementationType;

                if (logic.RegisteredImporters.ContainsKey(operType))
                {
                    newOper = autofac.ResolveNamed <IOperation>(operType,
                                                                new NamedParameter("config",
                                                                                   JsonConvert.DeserializeObject(operation.Config,
                                                                                                                 logic.RegisteredImporters[operType])));
                }

                else
                {
                    newOper = autofac.ResolveNamed <IOperation>(operType,
                                                                new NamedParameter("config",
                                                                                   JsonConvert.DeserializeObject(operation.Config,
                                                                                                                 logic.RegisteredExporters[operType])));
                }

                if (newOper == null)
                {
                    continue;
                }

                newOper.Properties.Id        = operation.Id;
                newOper.Properties.Number    = operation.Number;
                newOper.Properties.Name      = operation.Name;
                newOper.Properties.IsDefault = operation.IsDefault;

                Operations.Add(newOper);
            }

            this.autofac = autofac;
        } //ctor
Esempio n. 8
0
        public ContentResult CreateSchedule([FromBody] DtoSchedule newSchedule)
        {
            try
            {
                var id = logic.CreateSchedule(newSchedule);

                return(GetSuccessfulResult(id.ToString()));
            }
            catch
            {
                return(GetInternalErrorResult());
            }
        }
Esempio n. 9
0
        public RTask(ILifetimeScope autofac, IPostMaster postMaster, IRepository repository,
                     IClientControl monik, IMapper mapper, IArchiver archiver, ITelegramBotClient botClient,
                     int id, string reportName, string template, DtoSchedule schedule, string connStr, string query,
                     long chatId, RRecepientGroup sendAddress, int tryCount, int timeOut,
                     RReportType reportType, int reportId, bool htmlBody, bool jsonAttach)
        {
            Type = reportType;

            switch (Type)
            {
            case RReportType.Common:
                _dataEx = autofac.ResolveNamed <IDataExecutor>("commondataex");
                _viewEx = autofac.ResolveNamed <IViewExecutor>("commonviewex");
                break;

            case RReportType.Custom:
                _dataEx = autofac.ResolveNamed <IDataExecutor>(query);
                _viewEx = autofac.ResolveNamed <IViewExecutor>(template);
                break;

            default:
                throw new NotImplementedException();
            }

            _archiver         = archiver;
            _postMaster       = postMaster;
            Id                = id;
            ReportName        = reportName;
            Query             = query;
            ChatId            = chatId;
            ViewTemplate      = template;
            ReportId          = reportId;
            SendAddresses     = sendAddress;
            Schedule          = schedule;
            _repository       = repository;
            TryCount          = tryCount;
            QueryTimeOut      = timeOut;
            ConnectionString  = connStr;
            HasHtmlBody       = htmlBody;
            HasJsonAttachment = jsonAttach;
            _monik            = monik;
            _mapper           = mapper;
            _bot              = botClient;
        }