示例#1
0
        public async Task <ApiResponse> Handle(ApproveInvoiceCommand request, CancellationToken cancellationToken)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                var invoiceGeneration = _dbContext.InvoiceGeneration.AsQueryable().Where(x => x.JobId == request.jobId && x.IsDeleted == false).FirstOrDefault();
                if (invoiceGeneration != null)
                {
                    var invoiceDetails = _dbContext.InvoiceApproval.AsQueryable().Where(x => x.JobId == request.jobId).FirstOrDefault();
                    if (invoiceDetails == null)
                    {
                        InvoiceApproval obj = new InvoiceApproval();
                        obj.IsDeleted         = false;
                        obj.JobId             = request.jobId;
                        obj.IsInvoiceApproved = true;
                        obj.CreatedById       = request.CreatedById;
                        obj.CreatedDate       = request.CreatedDate;
                        await _dbContext.InvoiceApproval.AddAsync(obj);

                        await _dbContext.SaveChangesAsync();
                    }
                    else
                    {
                        var existRecord = await _dbContext.InvoiceApproval.FirstOrDefaultAsync(x => x.IsDeleted == false && x.JobId == request.jobId);

                        if (existRecord != null)
                        {
                            existRecord.IsInvoiceApproved = true;
                            existRecord.IsDeleted         = false;
                            existRecord.ModifiedById      = request.ModifiedById;
                            existRecord.ModifiedDate      = request.ModifiedDate;
                            await _dbContext.SaveChangesAsync();
                        }
                    }

                    List <ScheduleDetails> scheduleDetails = await _dbContext.ScheduleDetails.Where(x => x.IsDeleted == false && x.JobId == request.jobId).ToListAsync();

                    scheduleDetails.ForEach(x => x.IsActive = false);
                    await _dbContext.SaveChangesAsync();

                    response.StatusCode = StaticResource.successStatusCode;
                    response.Message    = "Invoice Approved successfully";
                }
                else
                {
                    response.StatusCode = StaticResource.notFoundCode;
                    response.Message    = "Invoice Not yet generated";
                }
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = StaticResource.SomethingWrong + ex.Message;
            }
            return(response);
        }
        public ActionResult SaveApprovalForm(InvoiceApproval data)
        {
            var test = db2.Invoices.Where(e => e.Id == data.InvoiceNo).FirstOrDefault().InvoiceAmount;


            if (test > data.ApprovalAmount)
            {
                data.InvoiceAmount = test;
                data.BranchId      = 1;
                data.UserId        = (int)Session["UserId"];
                data.DateAdded     = DateTime.Now;
                db2.InvoiceApprovals.Add(data);
                db2.SaveChanges();

                return(View("ApproveBills"));
            }
            else
            {
                var script =

                    "alert('Message from Server')";
                return(JavaScript(script));
            }
        }
示例#3
0
 public void Init()
 {
     invoiceApproval = new InvoiceApproval();
     AddActionClassesToList(invoiceApproval);
 }