public void CreateEntity(ResourceReserveViewModel viewModel)
        {
            var entity = this.ResourceReserveRepository.Create();

            entity.ID = Guid.NewGuid();
            entity.Name = viewModel.Name;
            entity.ResourceID = viewModel.ResourceID.Value;
            entity.StartDate = viewModel.StartDate.Value;
            entity.EndDate = viewModel.EndDate.Value;
            entity.ReserveUserID = this.GetCurrentAppUser().ID;
            entity.Memo = viewModel.Memo;

            this.ResourceReserveRepository.Add(entity);
            this.ResourceReserveRepository.SaveChanges();
        }
 private ResourceReserveViewModel EntityToViewModel(T_ResourceReserve entity)
 {
     var viewModel = new ResourceReserveViewModel
     {
         ID = entity.ID,
         Name = entity.Name,
         ResourceID = entity.ResourceID,
         StartDate = new SchedulerDateTime(entity.StartDate),
         EndDate = new SchedulerDateTime(entity.EndDate),
         ReserveUserID = entity.ReserveUserID,
         Memo = entity.Memo,
         Timestamp = entity.Timestamp
     };
     if (entity.Resource != null)
     {
         viewModel.ResourceName = entity.Resource.Name;
     }
     if (entity.ReserveUser != null)
     {
         viewModel.ReserveUserName = entity.ReserveUser.Name;
     }
     return viewModel;
 }
 private void CheckConcurrency(ResourceReserveViewModel viewModel, T_ResourceReserve entity)
 {
     if (!entity.Timestamp.SequenceEqual(viewModel.Timestamp))
     {
         throw new DbUpdateConcurrencyException();
     }
 }
        public void UpdateEntity(ResourceReserveViewModel viewModel)
        {
            var entity = this.ResourceReserveRepository.GetByID(viewModel.ID);

            this.CheckConcurrency(viewModel, entity);

            entity.Name = viewModel.Name;
            entity.StartDate = viewModel.StartDate.Value;
            entity.EndDate = viewModel.EndDate.Value;
            entity.Memo = viewModel.Memo;
            entity.Timestamp = viewModel.Timestamp;

            this.ResourceReserveRepository.SaveChanges();
        }
        public void RemoveEntity(ResourceReserveViewModel viewModel)
        {
            var entity = this.ResourceReserveRepository.GetByID(viewModel.ID);

            this.CheckConcurrency(viewModel, entity);

            this.ResourceReserveRepository.Remove(entity);
            this.ResourceReserveRepository.SaveChanges();
        }
        public ResourceReserveViewModel GetViewModelForCreate(Guid resourceID)
        {
            var viewModel = new ResourceReserveViewModel();

            viewModel.ResourceID = resourceID;

            return viewModel;
        }
        public ResourceReserveViewModel GetViewModel(Guid? resourceReserveID = null)
        {
            ResourceReserveViewModel viewModel;
            if (resourceReserveID.HasValue)
            {
                viewModel = this.EntityToViewModel(this.ResourceReserveRepository.GetByID(resourceReserveID.Value));
            }
            else
            {
                viewModel = new ResourceReserveViewModel();
                viewModel.ReserveUserID = this.GetCurrentAppUser().ID;
            }

            return viewModel;
        }