コード例 #1
0
        public Task Post([FromBody]Task task)
        {
            var context = new MobileTasksEntities();

            var resultTask = context.Tasks.SingleOrDefault(_ => _.Id == task.Id);
            if (resultTask != null)
            {
                if (resultTask.Sid != this.Sid)
                {
                    throw new HttpResponseException(HttpStatusCode.Unauthorized);
                }

                resultTask.Description = task.Description = task.Description;
                resultTask.DateDue = task.DateDue;
                resultTask.DateCompleted = task.DateCompleted;
                resultTask.IsCompleted = task.IsCompleted;
            }
            else
            {
				resultTask = task;

				resultTask.Sid = this.Sid;
				resultTask.DateCreated = DateTime.UtcNow;

                context.Tasks.Add(resultTask);
            }

            context.SaveChanges();
            return resultTask;
        }
コード例 #2
0
        public Task Get(int id)
        {
            var context = new MobileTasksEntities();

            var task = context.Tasks.SingleOrDefault(_ => _.Id == id);
            if (task != null && task.Sid != this.Sid)
            {
                throw new HttpResponseException(HttpStatusCode.Unauthorized);
            }

            return task;
        }
コード例 #3
0
		public void Delete(int id)
		{
			var context = new MobileTasksEntities();

			var task = context.Tasks.SingleOrDefault(_ => _.Id == id);
			if (task != null && task.Sid != this.Sid)
			{
				throw new HttpResponseException(HttpStatusCode.Unauthorized);
			}

			context.Tasks.Remove(task);
			context.SaveChanges();
		}
コード例 #4
0
        // GET api/Task
        public IEnumerable<Task> Get()
        {
            var context = new MobileTasksEntities();

            return context.Tasks.Where(_ => _.Sid == this.Sid);
        }