コード例 #1
0
ファイル: PaymentRepository.cs プロジェクト: ootybinu/ang
        public string CancelPayment(long PaymentId)
        {
            var result = "Success";

            try
            {
                var userid = Context.GetUser();
                var emp    = (from empl in EmployeeLoginMapping where empl.employeeid == userid select empl).FirstOrDefault();



                var payment = (from pd in PaymentDetail
                               where pd.Id == PaymentId
                               select pd).FirstOrDefault();
                if (payment != null)
                {
                    var bg = (from b in Bill
                              where b.Id == payment.BillNo
                              join us in UnitSummary on b.UnitId equals us.id
                              join bgd in BillGroupDetail on
                              b.MonthYear equals bgd.BillMonth.ToString("00") + bgd.BillYear.ToString()
                              where bgd.DivisionId == us.divisionid && bgd.BillGroupId == us.billgroupid
                              select bgd).FirstOrDefault();
                    if (bg != null && bg.Status != "Closed")
                    {
                        payment.Canceled   = true;
                        payment.CanceledAt = DateTime.Now;
                        payment.CanceledBy = emp.loginname;
                        PaymentDetail.Update(payment);
                        this.SaveChanges();
                    }
                    else
                    {
                        result = "Failed: BillGroup Already Closed";
                    }
                }
            }
            catch (Exception ex)
            {
                result = "Failed " + ex.Message;
            }

            return(result);
        }