Пример #1
0
        public HttpResponseMessage Post([FromBody] Task value)
        {
            if (ModelState.IsValid)
            {
                if (LogicTask.CheckIfExists(value))
                {
                    return(Request.CreateResponse(HttpStatusCode.Found, "Worker already exists in this project."));
                }
                return((LogicTask.AddTask(value)) ?
                       Request.CreateResponse(HttpStatusCode.Created) :
                       Request.CreateResponse(HttpStatusCode.BadRequest, "Can not add to DB."));
            }
            ;

            List <string> ErrorList = new List <string>();

            //if the code reached this part - the user is not valid
            foreach (var item in ModelState.Values)
            {
                foreach (var err in item.Errors)
                {
                    ErrorList.Add(err.ErrorMessage);
                }
            }

            return(Request.CreateResponse(HttpStatusCode.BadRequest, ErrorList));
        }
Пример #2
0
        public async Task <LogicTask> Get(int id)
        {
            await using var con = new SqlConnection(_connectionString);
            await using var com = new SqlCommand(Select_Query, con);
            var idParameter = new SqlParameter("@Id", SqlDbType.Int, sizeof(int)).Value = id as object;

            com.Parameters.Add(idParameter);
            var reader = await com.ExecuteReaderAsync();

            var logicTask = new LogicTask();

            DefaultMapper(reader, logicTask);
            return(logicTask);
        }
Пример #3
0
        public async Task <List <LogicTask> > GetList()
        {
            await using var con = new SqlConnection(_connectionString);
            await using var com = new SqlCommand(GetList_Query, con);

            SqlDataReader reader = await com.ExecuteReaderAsync();

            var logicTasks = new List <LogicTask>();

            while (reader.Read())
            {
                var logicTask = new LogicTask();
                DefaultMapper(reader, logicTask);
                logicTasks.Add(logicTask);
            }
            return(logicTasks);
        }
Пример #4
0
        /// <summary>
        /// Adds a timer that when elapsed will add the given task to tasks for logic.
        /// </summary>
        /// <param name="task"></param>
        protected void SetInboundTimer(LogicTask task)
        {
            //default interval
            int interval = 2500; //milliseconds

            // Create a timer with other interval.
            if (task is InboundLogicTask)
            {
                interval = ((InboundLogicTask)task).GetInterval();
            }

            System.Timers.Timer aTimer = new System.Timers.Timer(interval);
            InboundTimers.Add(aTimer);
            // Hook up the Elapsed event for the timer.
            aTimer.Elapsed += (e, v) => {
                logicTasks.Add(task);
                InboundTimers.Remove(aTimer);
                aTimer.Dispose();
            };
            aTimer.Enabled = true;
        }
Пример #5
0
        public HttpResponseMessage Put([FromBody] Task value)
        {
            if (ModelState.IsValid)
            {
                return((LogicTask.UpdateTask(value)) ?
                       Request.CreateResponse(HttpStatusCode.OK) :
                       Request.CreateResponse(HttpStatusCode.BadRequest, "Can not update in DB"));
            }
            ;

            List <string> ErrorList = new List <string>();

            //if the code reached this part - the user is not valid
            foreach (var item in ModelState.Values)
            {
                foreach (var err in item.Errors)
                {
                    ErrorList.Add(err.ErrorMessage);
                }
            }

            return(Request.CreateResponse(HttpStatusCode.BadRequest, ErrorList));
        }
Пример #6
0
 public HttpResponseMessage GetWorkerTasksDictionary(int id)
 {
     return(Request.CreateResponse(HttpStatusCode.OK, LogicTask.GetWorkerTasksDictionary(id)));
 }
Пример #7
0
 public HttpResponseMessage GetTasksWithUserAndProjectByUserId(int userId)
 {
     return(Request.CreateResponse(HttpStatusCode.OK, LogicTask.GetTasksWithUserAndProjectByUserId(userId)));
 }
Пример #8
0
 public void DefaultMapper(IDataReader reader, LogicTask entity)
 {
     entity.Id          = (int)reader["Id"];
     entity.Description = reader["Descrition"].ToString();
 }