Example #1
0
        public async Task <IActionResult> PostBill(AccidentBill bill)
        {
            try
            {
                var currentUser = (from u in dbContext.Users
                                   where u.Email == User.Identity.Name
                                   select u).FirstOrDefault();

                FMSAccidentalCheck check = (from c in dbContext.FMSAccidentalCheckList
                                            where c.Id == bill.CheckPointId
                                            select c).SingleOrDefault();
                check.MaintenanceStatus = CheckMaintenanceStatus.InProgress;
                check.Remarks           = bill.Remarks;
                FMSAccidentalCheckComment newComment = new FMSAccidentalCheckComment()
                {
                    Id = Guid.NewGuid(),
                    FMSAccidentalCheckId = check.Id,
                    FMSAccidentId        = check.FMSAccidentId,
                    Comment       = bill.BillAmount.ToString(),
                    FMSUserId     = new Guid((from u in dbContext.Users where u.Email == User.Identity.Name select u.Id).SingleOrDefault()),
                    FMSVehicleId  = check.FMSVehicleId,
                    VehicleNumber = check.VehicleNumber,
                    LastUpdated   = DateTime.Now,
                    Mentions      = ""
                };

                await dbContext.FMSAccidentalCheckComments.AddAsync(newComment);

                bill.Id = new Guid();
                await dbContext.AccidentBills.AddAsync(bill);

                check.CommentCount = await(from c in dbContext.FMSAccidentalCheckComments
                                           where c.FMSAccidentalCheckId == bill.CheckPointId
                                           select c).CountAsync();
                Accident accident = await dbContext.Accidents.Where(x => x.Id == check.FMSAccidentId).Select(x => x).SingleOrDefaultAsync();

                accident.LastUpdated = PakistanDateTime.Now;
                check.LastUpdated    = PakistanDateTime.Now;
                await dbContext.SaveChangesAsync();

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.ToString()));
            }
        }
Example #2
0
 public async Task <IActionResult> GetBill(ApiRequest request)
 {
     try
     {
         AccidentBill Bill = await(from b in dbContext.FMSAccidentalCheckList
                                   where b.Id == request.FMSAccidentalCheckId
                                   select new AccidentBill()
         {
             Remarks = b.Remarks
         }).FirstOrDefaultAsync();
         if (Bill == null)
         {
             Bill = new AccidentBill();
         }
         return(Ok(Bill));
     }
     catch (Exception)
     {
         return(BadRequest());
     }
 }