Пример #1
0
        public ActionResult <dynamic> Delete(LendCache cache)
        {
            LendPiece lend; string message = string.Empty;

            if ((lend = context.LendPieces.Where(l => l.lendId == cache.lend_id && !l.deleted).FirstOrDefault()) != null)
            {
                lend.deleted = true;
                context.LendPieces.Update(lend);
                context.SaveChanges();
                log.Information("Delete lend piece, id -> " + lend.lendId);
                return(new { success = true });
            }
            else
            {
                message = "Can't define lending piece by id, -> " + cache.lend_id;
            }
            return(Return500Error(message));
        }
Пример #2
0
        public ActionResult <dynamic> Create(LendCache cache)
        {
            LendPiece lend = new LendPiece()
            {
                lendBody  = HttpUtility.UrlDecode(cache.lend_body),
                createdAt = DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
                deleted   = false
            };

            context.LendPieces.Add(lend);
            context.SaveChanges();
            log.Information("Create new lend piece, id -> " + lend.lendId);
            return(new { success = true, data = new {
                             lend_id = lend.lendId,
                             lend_body = lend.lendBody,
                             created_at = lend.createdAt
                         } });
        }
Пример #3
0
        public ActionResult <dynamic> Update(LendCache cache)
        {
            LendPiece lend; string message = string.Empty;

            if ((lend = context.LendPieces.Where(l => l.lendId == cache.lend_id && !l.deleted).FirstOrDefault()) != null)
            {
                lend.lendBody = HttpUtility.UrlDecode(cache.lend_body);
                context.LendPieces.Update(lend);
                context.SaveChanges();
                log.Information("Update lend piece, id -> " + lend.lendId);
                return(new { success = true, data = new {
                                 lend_id = lend.lendId,
                                 lend_body = lend.lendBody,
                                 created_at = lend.createdAt
                             } });
            }
            else
            {
                message = "Can't define lending piece by id, -> " + cache.lend_id;
            }
            return(Return500Error(message));
        }