示例#1
0
        public async Task <ResultModel <Dictionary <string, object> > > Create(Dictionary <string, object> model)
        {
            try
            {
                IEnumerable <AddedColumn> addedColumns = await _addedColumn.GetAll();

                Contact entity      = MapToEntity(model, addedColumns);
                var     checkunique = await _contact.GetAll(t => t.Name == entity.Name);

                if (checkunique.Any())
                {
                    return(ResultModel <Dictionary <string, object> > .GetErrorResult(new List <ResultErrorModel> {
                        new ResultErrorModel(ResultErrorTypeEnum.UniqueFieldError, new string[] { "Contact Name" })
                    }));
                }
                entity = await _contact.Add(entity);

                await _contact.Commit();

                model = MapToModel(entity);
                return(ResultModel <Dictionary <string, object> > .GetSuccessResult(model));
            }
            catch (Exception e)
            {
                await _contact.Abort();

                ResultErrorModel error = new ResultErrorModel(e);
                return(ResultModel <Dictionary <string, object> > .GetExceptionResult(error));
            }
        }