Example #1
0
        public DataSourceResult Save(BlindsModel viewModel, ModelStateDictionary modelState)
        {
            if (viewModel != null && modelState.IsValid)
            {
                var repo   = this.RepoFactory.Get <BlindRepository>();
                var entity = repo.GetById(viewModel.Id);

                if (entity == null)
                {
                    entity = new Blind();
                    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));
            }
        }
Example #2
0
        public DataSourceResult Delete(BlindsModel viewModel)
        {
            var repo   = this.RepoFactory.Get <BlindRepository>();
            var entity = repo.GetById(viewModel.Id);

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

            repo.SaveChanges();
            return(null);
        }