Esempio n. 1
0
        public async Task <ActionResult <AccountVM> > UpdateAsync(long accountID, AccountVM value)
        {
            try
            {
                // VALIDATE
                var validateMessage = await this.ValidateAsync(value);

                var validateResult = this.GetValue(validateMessage);
                if (!validateResult)
                {
                    return(validateMessage.Result);
                }

                // LOCATE DATA
                var data = await this.GetDataQuery().Where(x => x.AccountID == accountID).FirstOrDefaultAsync();

                if (data == null)
                {
                    return(this.NotFoundResponse());
                }

                // APPLY
                data.Text       = value.Text;
                data.Type       = (short)value.Type;
                data.ClosingDay = value.ClosingDay;
                data.DueDay     = value.DueDay;
                data.Active     = value.Active;
                await this.dbContext.SaveChangesAsync();

                // RESULT
                var result = AccountVM.Convert(data);
                return(this.OkResponse(result));
            }
            catch (Exception ex) { return(this.ExceptionResponse(ex)); }
        }
Esempio n. 2
0
 public async Task <ActionResult <AccountVM> > UpdateAsync(long id, [FromBody] AccountVM value)
 {
     if (value == null)
     {
         return(this.BadRequest(this.ModelState));
     }
     return(await this.GetService <AccountsService>().UpdateAsync(id, value));
 }
Esempio n. 3
0
        private async Task <ActionResult <List <AccountVM> > > GetDataAsync(long accountID, string searchText)
        {
            try
            {
                var query = this.GetDataQuery();
                if (accountID != 0)
                {
                    query = query.Where(x => x.AccountID == accountID);
                }
                if (!string.IsNullOrEmpty(searchText))
                {
                    query = query.Where(x => x.AccountID != 0 && x.Text.Contains(searchText));
                }

                var data = await query.OrderBy(x => x.Type).ThenBy(x => x.Text).ToListAsync();

                var result = data.Select(x => AccountVM.Convert(x)).ToList();
                return(this.OkResponse(result));
            }
            catch (Exception ex) { return(this.ExceptionResponse(ex)); }
        }
Esempio n. 4
0
        public async Task <ActionResult <AccountVM> > CreateAsync(AccountVM value)
        {
            try
            {
                var user = this.GetService <Helpers.User>();

                // VALIDATE
                var validateMessage = await this.ValidateAsync(value);

                var validateResult = this.GetValue(validateMessage);
                if (!validateResult)
                {
                    return(validateMessage.Result);
                }

                // NEW MODEL
                var data = new AccountData()
                {
                    ResourceID = user.ResourceID,
                    Text       = value.Text,
                    Type       = (short)value.Type,
                    Active     = value.Active,
                    ClosingDay = value.ClosingDay,
                    DueDay     = value.DueDay,
                    RowStatus  = 1
                };

                // APPLY
                await this.dbContext.Accounts.AddAsync(data);

                await this.dbContext.SaveChangesAsync();

                // RESULT
                var result = AccountVM.Convert(data);
                return(this.CreatedResponse("accounts", result.AccountID, result));
            }
            catch (Exception ex) { return(this.ExceptionResponse(ex)); }
        }
Esempio n. 5
0
        private async Task <ActionResult <bool> > ValidateAsync(AccountVM value)
        {
            try
            {
                // VALIDATE DUPLICITY
                if (await this.GetDataQuery().CountAsync(x => x.AccountID != value.AccountID && x.Text == value.Text) != 0)
                {
                    return(this.WarningResponse(this.GetTranslation("ACCOUNTS_ACCOUNT_TEXT_ALREADY_EXISTS_WARNING")));
                }

                // VALIDATE CREDIT CARD
                if (value.Type == enAccountType.CreditCard)
                {
                    if (!value.DueDay.HasValue || value.DueDay <= 0 || value.DueDay >= 31)
                    {
                        return(this.WarningResponse(this.GetTranslation("ACCOUNTS_INVALID_DUE_DAY_WARNING")));
                    }
                }

                // RESULT
                return(this.OkResponse(true));
            }
            catch (Exception ex) { return(this.ExceptionResponse(ex)); }
        }