Ejemplo n.º 1
0
        private async Task <ContactTableDetailEditOutput> ExecuteNew(ContactTableDetailEditInput input)
        {
            var contact = new Contact(input.Contact);

            contact.DistributorId = input.DistributorId;
            var added = await this._contactRepository.AddAsync(contact);

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

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

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

                return(new ContactTableDetailEditOutput(null, false, "Error: Could Not Add Contact"));
            }
        }
Ejemplo n.º 2
0
        private async Task <ContactTableDetailEditOutput> ExecuteUpdate(ContactTableDetailEditInput input)
        {
            var contact = await this._contactRepository.GetEntityAsync(e => e.Id == input.Contact.Id);

            contact.Set(input.Contact);
            var updated = await this._contactRepository.UpdateAsync(contact);

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

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

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

                return(new ContactTableDetailEditOutput(null, false, "Error: Could Not Update Contact,Please Contact Admin"));
            }
        }
Ejemplo n.º 3
0
        public async Task <ContactTableDetailEditOutput> Execute(ContactTableDetailEditInput 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 ContactTableDetailEditOutput(null, false, "Error: No Such Edit Option"));
            }
        }