private HourCode FindDuplicateOf(HourCode hourCode)
 {
     return HourCodes
         .FirstOrDefault(code =>
             code.Code.Equals(hourCode.Code) &&
             code.Name.Equals(hourCode.Name));
 }
        public void Should()
        {
            var hourCode = new HourCode();
            var hourUsage = new HourUsage();
            hourUsage.SetHourCode(hourCode);

            Assert.That(hourUsage.HourCode, Is.EqualTo(hourCode));
            Assert.That(hourCode.Usages, Contains.Item(hourUsage));
        }
        public HourCode AddHourCode(string code, string name)
        {
            if (string.IsNullOrWhiteSpace(code) || string.IsNullOrWhiteSpace(name))
            {
                throw new HourGlassUserException(ExceptionType.InvalidHourCode, code, name);
            }

            var hourCode = new HourCode {Code = code.Trim(), Name = name.Trim()};
            var duplicate = FindDuplicateOf(hourCode);
            if (duplicate != null)
            {
                return duplicate;
            }

            _repo.Save(hourCode);
            HourCodes.Add(hourCode);
            return hourCode;
        }
 public HourCode Save(HourCode hourCode)
 {
     return _repo.Save(hourCode);
 }
 public HourCode Remove(HourCode hourCode)
 {
     HourCodes.Remove(hourCode);
     return _repo.Delete(hourCode);
 }
 public HourCodeViewModel(IHourCodeProvider hourCodeProvider, HourCode hourCode)
 {
     HourCode = hourCode;
     _hourCodeProvider = hourCodeProvider;
     SaveCommand = new DelegateCommand(Save);
 }