コード例 #1
0
        public void InvalidRotationNull()
        {
            var req = new AddTimeEntryRequest()
            {
                Rotation = null,
            };

            validator.ShouldHaveValidationErrorFor(x => x.Rotation, req);
        }
コード例 #2
0
        public void InvalidStudentId()
        {
            var req = new AddTimeEntryRequest()
            {
                StudentId = 0,
            };

            validator.ShouldHaveValidationErrorFor(x => x.StudentId, req);
        }
コード例 #3
0
        public void InvalidPreceptorId()
        {
            var req = new AddTimeEntryRequest()
            {
                PreceptorId = 0,
            };

            validator.ShouldHaveValidationErrorFor(x => x.PreceptorId, req);
        }
コード例 #4
0
        public void InvalidHoursZero()
        {
            var req = new AddTimeEntryRequest()
            {
                Hours = 0,
            };

            validator.ShouldHaveValidationErrorFor(x => x.Hours, req);
        }
コード例 #5
0
        public void InvalidDateInPast()
        {
            var req = new AddTimeEntryRequest()
            {
                Date = new DateTime(1999, 1, 1).ToString(),
            };

            validator.ShouldHaveValidationErrorFor(x => x.Date, req);
        }
コード例 #6
0
        public async Task <TimeEntryResponse> AddTimeEntryAsync(AddTimeEntryRequest req)
        {
            var entry  = _mapper.Map(req);
            var result = _repo.Add(entry);
            await _repo.UnitOfWork.SaveChangesAsync();

            //TODO: Look for all confirm results, and hopefully one day get rid of them
            //the add is not linking the foreign key objects....
            var confirmResult = await _repo.GetEntryAsync(result.Id);

            return(_mapper.Map(confirmResult));
        }
コード例 #7
0
        public async Task <bool> AddTimeEntry(AddTimeEntryRequest entry)
        {
            var json = JsonConvert.SerializeObject(entry, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore, DateFormatString = "yyyy-MM-dd"
            });

            var result = await _httpClient.PostAsync("time_entries.json", new StringContent(json, Encoding.UTF8, "application/json"));

            var whatwentwrong = await result.Content.ReadAsStringAsync();

            return(result.IsSuccessStatusCode);
        }
コード例 #8
0
        public TimeEntry Map(AddTimeEntryRequest req)
        {
            if (req == null)
            {
                return(null);
            }

            return(new TimeEntry()
            {
                Date = DateTime.Parse(req.Date),
                Hours = req.Hours,
                Notes = req.Notes,
                Rotation = req.Rotation,
                StudentId = req.StudentId,
                TeacherId = req.PreceptorId,
            });
        }