Ejemplo n.º 1
0
        public virtual async Task <ManagerResult> DeleteAsync(TKey id)
        {
            try
            {
                T found = await Store.FindByIdAsync(id);

                if (found == null)
                {
                    return(new ManagerResult(ManagerErrors.RecordNotFound));
                }

                ManagerResult logicCheckResult = OnDeleteLogicCheck(found);

                if (!logicCheckResult.Success)
                {
                    return(logicCheckResult);
                }

                await Store.DeleteAsync(found);
            }
            catch (Exception e)
            {
                return(e.CreateManagerResult());
            }

            return(new ManagerResult());
        }
Ejemplo n.º 2
0
        public virtual async Task <ManagerResult> UpdateAsync(T entity)
        {
            T recordToUpdate = await FindByIdAsync(entity.Id);

            if (recordToUpdate == null)
            {
                return(new ManagerResult(ManagerErrors.RecordNotFound));
            }

            try
            {
                T possibleDuplicate = await FindUniqueAsync(entity);

                if ((possibleDuplicate != null) && (!possibleDuplicate.Id.Equals(recordToUpdate.Id)))
                {
                    return(new ManagerResult(ManagerErrors.DuplicateOnUpdate));
                }

                ManagerResult logicCheckResult = OnUpdateLogicCheck(entity);

                if (!logicCheckResult.Success)
                {
                    return(logicCheckResult);
                }

                OnUpdatePropertyValues(recordToUpdate, entity);

                await Store.UpdateAsync(recordToUpdate);
            }
            catch (NotImplementedException)
            {
                ManagerResult logicCheckResult = OnUpdateLogicCheck(entity);

                if (!logicCheckResult.Success)
                {
                    return(logicCheckResult);
                }

                OnUpdatePropertyValues(recordToUpdate, entity);

                await Store.UpdateAsync(recordToUpdate);
            }
            catch (Exception e)
            {
                return(e.CreateManagerResult());
            }

            return(new ManagerResult());
        }
Ejemplo n.º 3
0
        public virtual async Task <ManagerResult> CreateAsync(T entity)
        {
            try
            {
                T duplicate = await FindUniqueAsync(entity);

                if (duplicate != null)
                {
                    return(new ManagerResult(ManagerErrors.DuplicateOnCreate));
                }

                ManagerResult logicCheckResult = OnCreateLogicCheck(entity);

                if (!logicCheckResult.Success)
                {
                    return(logicCheckResult);
                }

                await Store.CreateAsync(entity);
            }
            catch (NotImplementedException)
            {
                ManagerResult logicCheckResult = OnCreateLogicCheck(entity);

                if (!logicCheckResult.Success)
                {
                    return(logicCheckResult);
                }

                await Store.CreateAsync(entity);
            }
            catch (Exception e)
            {
                return(e.CreateManagerResult());
            }

            return(new ManagerResult());
        }