public async static Task <bool> Edit(this Purchase purchase, HSBorsDb db, AddPurchaseRequest request, SingleResponse <object> response)
        {
            if (!request.CheckValidation(response))
            {
                return(false);
            }
            var entity         = request.ToEntity(true);
            var existingEntity = await db.GetPurchase(entity);

            if (existingEntity == null)
            {
                response.ErrorCode = (int)ErrorHandler.ErrorCode.NoContent;
                return(false);
            }

            existingEntity.UpdateProperty(request.ToEntity());

            return(true);
        }
Beispiel #2
0
        public static Purchase ToEntity(this AddPurchaseRequest request, bool add_id = false)
        {
            Purchase purchase = new Purchase
            {
                deposit_id             = request.deposit_id,
                amount                 = request.amount,
                bank_copartner_id      = request.bank_copartner_id,
                bank_copartner_intrest = request.bank_copartner_intrest,
                bank_copartner_percent = request.bank_copartner_percent,
                buyer_id               = request.buyer_id,
                create_date            = DateTime.Now,
                creator_id             = 1
            };

            if (add_id)
            {
                purchase.id = request.id;
            }
            return(purchase);
        }
Beispiel #3
0
        public static List <AddPurchaseRequest> ToPurchasesRequest(this AddDepositRequest request, bool add_id = false)
        {
            List <AddPurchaseRequest> purchases = new List <AddPurchaseRequest>();

            foreach (var item in request.purchases)
            {
                AddPurchaseRequest purchase = new AddPurchaseRequest
                {
                    amount                 = item.amount,
                    bank_copartner_id      = item.bank_copartner_id,
                    bank_copartner_intrest = item.bank_copartner_intrest,
                    bank_copartner_percent = item.bank_copartner_percent,
                    buyer_id               = item.buyer_id,
                    deposit_id             = request.id
                };
                if (add_id)
                {
                    purchase.id = item.id;
                }
                purchases.Add(purchase);
            }
            return(purchases);
        }