public DataSourceResult Save(RailsModel viewModel, ModelStateDictionary modelState)
        {
            if (viewModel != null && modelState.IsValid)
            {
                var repo   = this.RepoFactory.Get <RailRepository>();
                var entity = repo.GetById(viewModel.Id);

                var exists = repo.GetIfExists(viewModel.BlindTypeId, viewModel.Color, viewModel.Id);

                if (exists)
                {
                    return(new DataSourceResult
                    {
                        Errors = GlobalConstants.RailExistsMessage
                    });
                }

                if (entity == null)
                {
                    entity = new Rail();
                    repo.Add(entity);
                }

                Mapper.Map(viewModel, entity);

                try
                {
                    repo.SaveChanges();
                    viewModel.Id = entity.Id;
                }
                catch (DbEntityValidationException e)
                {
                    return(new DataSourceResult
                    {
                        Errors = this.HandleDbEntityValidationException(e)
                    });
                }

                return(null);
            }
            else
            {
                return(this.HandleErrors(modelState));
            }
        }
        public DataSourceResult Delete(RailsModel viewModel, ModelStateDictionary modelState)
        {
            if (viewModel != null && modelState.IsValid)
            {
                var repo   = this.RepoFactory.Get <RailRepository>();
                var entity = repo.GetById(viewModel.Id);

                entity.Deleted   = true;
                entity.DeletedOn = DateTime.Now;

                repo.SaveChanges();
                return(null);
            }
            else
            {
                return(this.HandleErrors(modelState));
            }
        }