示例#1
0
        public ActionResult <Day> Add(DayDTO model)
        {
            Day day = _dayRepository.GetByWeekAndDay(model.TemplateName, model.WeekNr, model.DayNr);

            if (day != null)
            {
                return(BadRequest("A day with this weekNr and dayNr already exists for this template"));
            }
            else
            {
                try
                {
                    Day      dayToAdd       = new Day(model.TemplateName, model.WeekNr, model.DayNr);
                    Activity activitySick   = _activityRepository.GetAllIncludingSickAbsent().SingleOrDefault(a => a.ActivityType == ActivityType.ZIEK);
                    Activity activityAbsent = _activityRepository.GetAllIncludingSickAbsent().SingleOrDefault(a => a.ActivityType == ActivityType.AFWEZIG);
                    dayToAdd.AddDayActivity(new DayActivity(dayToAdd, activitySick, TimeOfDay.VOLLEDIG));
                    dayToAdd.AddDayActivity(new DayActivity(dayToAdd, activityAbsent, TimeOfDay.VOLLEDIG));
                    _dayRepository.Add(dayToAdd);
                    _dayRepository.SaveChanges();
                    return(Ok(dayToAdd));
                }
                catch (Exception ex)
                {
                    return(BadRequest(ex.Message));
                }
            }
        }
示例#2
0
        public IActionResult Post(DayDTO dto)
        {
            try
            {
                Day = ApiRepository.DtoToDay(dto);

                var dayExists = dayData.GetByDate(DateTime.Now.Date, User.Identity.Name);

                if (dayExists != null)
                {
                    return(BadRequest("Day already exists!"));
                }

                dayData.Add(Day);

                if (dayData.Commit() > 0)
                {
                    return(CreatedAtAction("GetById", new { id = Day.DayId }, Day));
                }
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }

            return(BadRequest());
        }
示例#3
0
        /// <summary>
        /// This method sets the generator DTO by reading input data xml file.
        /// </summary>
        private void SetGeneratorData()
        {
            XDocument xdoc = XDocument.Load(filePath);

            Console.WriteLine(generatorName);
            var selectGenerator = from x in xdoc.Descendants(generatorName) select x;

            if (null == generatorDTOList)
            {
                generatorDTOList = new List <GeneratorDTO>();
            }

            foreach (var generator in selectGenerator)
            {
                var          selectGeneration = from genResult in generator.Descendants(ApplicationConstant.DAY) select genResult;
                GeneratorDTO generatorDTO     = new GeneratorDTO();
                generatorDTO.Name = generator.Element(ApplicationConstant.NAME).Value;

                if (generator.Element(ApplicationConstant.LOCATION) != null)
                {
                    generatorDTO.Location = generator.Element(ApplicationConstant.LOCATION).Value;
                }

                if (generator.Element(ApplicationConstant.TOTAL_HEAT_INPUT) != null)
                {
                    generatorDTO.TotalHeatInput = double.Parse(generator.Element(ApplicationConstant.TOTAL_HEAT_INPUT).Value);
                }

                if (generator.Element(ApplicationConstant.ACTUAL_NET_GENERATION) != null)
                {
                    generatorDTO.ActualNetGeneration = double.Parse(generator.Element(ApplicationConstant.ACTUAL_NET_GENERATION).Value);
                }

                if (generator.Element(ApplicationConstant.EMISSIONS_RATING) != null)
                {
                    generatorDTO.EmissionsRating = double.Parse(generator.Element(ApplicationConstant.EMISSIONS_RATING).Value);
                }

                if (null == generatorDTO.Generation)
                {
                    generatorDTO.Generation = new List <DayDTO>();
                }

                foreach (var generation in selectGeneration)
                {
                    DayDTO dayDTO = new DayDTO();
                    dayDTO.Date   = DateTime.Parse(generation.Element(ApplicationConstant.DATE).Value).ToUniversalTime();
                    dayDTO.Energy = double.Parse(generation.Element(ApplicationConstant.ENERGY).Value);
                    dayDTO.Price  = double.Parse(generation.Element(ApplicationConstant.PRICE).Value);

                    generatorDTO.Generation.Add(dayDTO);
                }

                generatorDTOList.Add(generatorDTO);
            }
        }
示例#4
0
 public static Day DtoToDay(DayDTO day, Day ent = null)
 {
     if (day != null)
     {
         return(ent = ent ?? new Day
         {
             DayId = day.DayId,
             Date = day.Date,
             OwnerName = day.OwnerName,
         });
     }
     return(null);
 }
示例#5
0
 public static DayDTO DayToDto(Day day, DayDTO dto = null)
 {
     if (day != null)
     {
         return(dto = dto ?? new DayDTO
         {
             DayId = day.DayId,
             Date = day.Date,
             OwnerName = day.OwnerName,
         });
     }
     return(null);
 }
示例#6
0
        public void AddTemplateDay_TwiceSameDay_ReturnBadRequest()
        {
            Day    existingDay = _dummyDBContext.Day6;
            DayDTO newDayDTO   = new DayDTO()
            {
                TemplateName = "tweede_week_eerste_dag",
                DayNr        = 1,
                WeekNr       = 2
            };

            _dayRepository.Setup(d => d.GetByWeekAndDay(existingDay.TemplateName, existingDay.WeekNr, existingDay.DayNr)).Returns(existingDay);


            ActionResult <Day> actionResult = _controller.Add(newDayDTO);

            Assert.IsType <BadRequestObjectResult>(actionResult?.Result);
        }
示例#7
0
        private void FillWindow()
        {
            _userRepository = new UserRepository();
            _userService    = new UserService(_userRepository);
            this.user       = _userService.FindById(user.Id);
            if (user.Gender == true)
            {
                lbGender.Content = "Male";
            }
            else
            {
                lbGender.Content = "Female";
            }
            lbAge.Content    = user.Age;
            lbWeight.Content = user.Weight;
            lbHeight.Content = user.Height;
            lbName.Content   = user.FirstName + " " + user.LastName;
            tblCalories.Text = user.RecommentedCountOfCalories.ToString();

            lbRecommendedCalories.Content = user.RecommentedCountOfCalories.ToString();
            lbRecommendedCarbs.Content    = user.RecommentedCountOfCarbohydrates.ToString();
            lbRecommendedFats.Content     = user.RecommentedCountOfFats.ToString();
            lbRecommendedProteins.Content = user.RecommentedCountOfProteins.ToString();

            cbProducts.SelectedIndex = -1;
            tboxProductWeight.Text   = "";
            DayDTO day = user.FindDay(Convert.ToDateTime(Calendar1.SelectedDate));

            if (day != null)
            {
                day.FillDay();
                lbAtedCalories.Content     = day.AtedCalories.ToString();
                lbAtedCarbs.Content        = day.AtedCarbohydrates.ToString();
                lbAtedFats.Content         = day.AtedFats.ToString();
                lbAtedProteins.Content     = day.AtedProteins.ToString();
                lbAtedProducts.ItemsSource = day.AtedProducts.ToList();
            }
            else
            {
                lbAtedCalories.Content = 0;
                lbAtedCarbs.Content    = 0;
                lbAtedFats.Content     = 0;
                lbAtedProteins.Content = 0;
            }
        }
        private ICollection <DayDTO> CreateMockDayDtos()
        {
            var day1 = new DayDTO()
            {
                Date          = _sampleDate,
                ReportedHours = 8
            };

            var day2 = new DayDTO()
            {
                Date          = _sampleDate,
                ReportedHours = 7
            };

            return(new List <DayDTO> {
                day1, day2
            });
        }
示例#9
0
 private void Calendar1_SelectedDatesChanged(object sender, SelectionChangedEventArgs e)
 {
     if (Calendar1.SelectedDate.HasValue == true)
     {
         DayDTO day = user.Days.FirstOrDefault(t => t.Date.CompareTo(Calendar1.SelectedDate.Value) == 0);
         if (day != null)
         {
             FillWindow();
         }
         else
         {
             lbAtedCalories.Content     = 0;
             lbAtedCarbs.Content        = 0;
             lbAtedFats.Content         = 0;
             lbAtedProteins.Content     = 0;
             lbAtedProducts.ItemsSource = null;
         }
     }
 }
示例#10
0
        public void AddTemplateDay_Succeeds()
        {
            DayDTO dayDTO = new DayDTO()
            {
                TemplateName = "tweede_week_eerste_dag",
                DayNr        = 1,
                WeekNr       = 2
            };

            ActionResult <Day> actionResult = _controller.Add(dayDTO);
            var response = actionResult?.Result as OkObjectResult;
            Day day      = response?.Value as Day;


            Assert.Equal("tweede_week_eerste_dag", day.TemplateName);

            _dayRepository.Verify(d => d.Add(It.IsAny <Day>()), Times.Once());
            _dayRepository.Verify(d => d.SaveChanges(), Times.Once());
        }
示例#11
0
        public IActionResult Put(int id, DayDTO dto)
        {
            try
            {
                Day = dayData.GetById(id);
                if (Day == null)
                {
                    return(NotFound($"Could not find day with id:{id}"));
                }

                ApiRepository.DtoToDay(dto, Day);
                dayData.Update(Day);

                if (dayData.Commit() > 0)
                {
                    return(Ok("Updated!"));
                }
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }
            return(BadRequest());
        }