Esempio n. 1
0
        public async Task<HttpResponseMessage> AddChecklist(ChecklistDto newChecklist)
        {
            if(newChecklist == null)
                throw new InvalidQueryException("Received an invalid checklist format.");
            if(newChecklist.Id.HasValue)
                throw new InvalidQueryException("Checklist may not specify an ID.");

            InitializeNewChecklist(newChecklist);        

            await _repository.UpsertChecklist(newChecklist);
            var response = Request.CreateResponse(HttpStatusCode.Created);
            response.Headers.Location = new Uri(Request.RequestUri, newChecklist.Id.ToString());
            return response;
        }
Esempio n. 2
0
        public IActionResult PostChecklist([FromBody] Checklist entity)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = _userManager.GetUserId(this.User);

            entity.UserId = user;

            Checklist    checklist    = _service.Create(entity);
            ChecklistDto checklistDto = _mapper.Map <ChecklistDto>(checklist);

            return(Ok(checklistDto));
        }
Esempio n. 3
0
        public void TestJson()
        {
            var Checklist = new ChecklistDto {
                Title = "Test Title",
                Description = "Some random description",
                FileNumber = 12345,
                SurveyLocation = new SurveyLocation {
                    LandDistrict = new LandDistrictDto {
                        Name = "The Rocky Mountains",
                        NtsMap = "I don't know what NtsMap is",
                        Coordinate = new GeoCoordinate {
                            Latitude = 48.441271,
                            Longitude = -123.344066
                        }
                    },
                    Coordinate = new GeoCoordinate {
                        Latitude = 48.441271,
                        Longitude = -123.344066
                    },
                    Address = new CivicAddress {
                        AddressLine1 = "123 Fake Street",
                        AddressLine2 = null,
                        Building = "Buckingham Palaca",
                        City = "London",
                        CountryRegion = "England",
                        FloorLevel = null,
                        PostalCode = "123abc",
                        StateProvince = "Kenya"
                    }
                },
                Items = new List<ChecklistItem>{
                    new ChecklistItem {
                        Text = "This is the first item",
                        Status = ChecklistItemStatus.Yes
                    },
                    new ChecklistItem {
                        Text = "This is the second item",
                        Status = ChecklistItemStatus.Unanswered
                    }
                }
            };

            Console.WriteLine(JsonConvert.SerializeObject(Checklist));
        }
Esempio n. 4
0
        public async Task<HttpResponseMessage> UpdateChecklistById(Guid id, ChecklistDto updatedChecklist)
        {
            if(updatedChecklist == null)
                throw new InvalidQueryException("Received an invalid checklist format.");

            if(!await _repository.ChecklistExists(id))
                throw new DocumentNotFoundException(id.ToString());

            updatedChecklist.Id = id;
            await _repository.UpsertChecklist(updatedChecklist);

            return Request.CreateResponse(HttpStatusCode.OK);
        }
Esempio n. 5
0
        private void InitializeNewChecklist(ChecklistDto checklist)
        {
            checklist.Id = Guid.NewGuid();
            checklist.Nonce = Guid.NewGuid();

            DateTime currentTime = DateTime.UtcNow;
            checklist.CreatedAt = currentTime;
            checklist.LastModified = currentTime;
        }
Esempio n. 6
0
 public Task UpsertChecklist(ChecklistDto checklist)
 {
     return Task.Run(() =>
     {
         try
         {
             return _collection.Save(checklist);
         }
         catch(Exception ex)
         {
             string errorMessage = String.Format(CultureInfo.InvariantCulture,
                 "Encountered an error while upserting a checklist with Id = {0};", checklist.Id);
             Log.Error(errorMessage);
             throw new RepositoryException(errorMessage, ex);
         }
     });
 }