Esempio n. 1
0
        public async Task UpdateAsync(int id, PaymentlogIM item)
        {
            var origin = await _db.Paymentlogs.FindAsync(id);

            var pl = _mapper.Map(item, origin);

            _db.Update(pl);
            await _db.SaveChangesAsync();
        }
Esempio n. 2
0
        public async Task CreateAsync(PaymentlogIM item)
        {
            var pl = _mapper.Map <Paymentlog>(item);

            pl.CreatedDate = DateTime.Now;
            pl.CreatedBy   = await _sessionStorageService.GetItemAsync <string>("username");

            await _db.AddAsync(pl);

            await _db.SaveChangesAsync();
        }
Esempio n. 3
0
        public async Task <IActionResult> PostPaymentlog([FromBody] PaymentlogIM paymentlog)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (paymentlog.PayType == 2)
            {
                paymentlog.Money = -paymentlog.Money;
            }

            var vm = _mapper.Map <Paymentlog>(paymentlog);

            _context.Paymentlogs.Add(vm);
            await _context.SaveChangesAsync();

            return(Ok(vm));
        }
Esempio n. 4
0
        public async Task <IActionResult> PutPaymentlog([FromRoute] int id, [FromBody] PaymentlogIM paymentlog)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != paymentlog.Id)
            {
                return(BadRequest());
            }

            if (paymentlog.PayType == 2)
            {
                paymentlog.Money = -paymentlog.Money;
            }

            var model = await _context.Paymentlogs.FirstOrDefaultAsync(d => d.Id == id);

            model = _mapper.Map(paymentlog, model);

            _context.Entry(model).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PaymentlogExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }