public async Task <DistributorEditOutput> ExecuteUpdate(DistributorEditInput input)
        {
            var distributor = await this._distributorRepository.GetEntityAsync(e => e.Id == input.DistributorId);

            distributor.Name        = input.Name;
            distributor.Description = input.Description;
            var updated = await this._distributorRepository.UpdateAsync(distributor);

            if (updated != null)
            {
                var count = await this._unitOfWork.Save();

                if (count > 0)
                {
                    return(new DistributorEditOutput(updated, true, "Success: Distributor Updated"));
                }
                else
                {
                    await this._unitOfWork.Undo();

                    return(new DistributorEditOutput(null, false, "Error: Update Failed, Please Contact Admin"));
                }
            }
            else
            {
                await this._unitOfWork.Undo();

                return(new DistributorEditOutput(null, false, "Error: Update Failed, Please Contact Admin"));
            }
        }
        public async Task <DistributorEditOutput> ExecuteNew(DistributorEditInput input)
        {
            var distributor = new Distributor(input.Name, input.Description);
            var added       = await this._distributorRepository.AddAsync(distributor);

            if (added != null)
            {
                var count = await this._unitOfWork.Save();

                if (count > 0)
                {
                    return(new DistributorEditOutput(added, true, "Success: Distributor Added"));
                }
                else
                {
                    await this._unitOfWork.Undo();

                    return(new DistributorEditOutput(null, false, "Error: Add Failed, Please Contact Admin"));
                }
            }
            else
            {
                await this._unitOfWork.Undo();

                return(new DistributorEditOutput(null, false, "Error: Add Failed, Please Contact Admin"));
            }
        }
        public async Task <DistributorEditOutput> Execute(DistributorEditInput input)
        {
            switch (input.EditAction)
            {
            case Boundaries.EditAction.Add:
                return(await this.ExecuteNew(input));

            case Boundaries.EditAction.Delete:
                return(await this.ExecuteDelete(input));

            case Boundaries.EditAction.Update:
                return(await this.ExecuteUpdate(input));

            default:
                return(new DistributorEditOutput(null, false, "Invalid Selection"));
            }
        }
 public async Task <DistributorEditOutput> ExecuteDelete(DistributorEditInput input)
 {
     return(new DistributorEditOutput(null, false, "Internal Error: Delete not implemented"));
 }