public IHttpActionResult SaveCustomerCharge(FrayteCustomerSpecificAdminCharges charge) { FrayteResult result = new FrayteResult(); result = new AdminChargesRepository().SaveCustomerCharge(charge); return(Ok(result)); }
public FrayteCustomerSpecificAdminCharges GetCustomerAdminCharges(int customerId) { try { FrayteCustomerSpecificAdminCharges charge = new FrayteCustomerSpecificAdminCharges(); charge.Charges = new List <AdminChargesTypes>(); var data = (from r in dbcontext.AdminCharges join u in dbcontext.Users on r.CustomerId equals u.UserId join ua in dbcontext.UserAdditionals on r.CustomerId equals ua.UserId where r.CustomerId == customerId && r.IsActive == true && r.OperationZoneId == UtilityRepository.GetOperationZone().OperationZoneId select new { CustomerName = u.CompanyName, CustomerId = r.CustomerId, AdminChargeId = r.AdminChargesId, CreatedBy = r.CreatedBy, ChargeType = r.ChargeType, Key = r.ShortName, Value = r.Name, Amount = r.Value, CreatedOn = r.CreatedOnUtc }).ToList(); charge = data.GroupBy(x => x.CustomerId) .Select(group => new FrayteCustomerSpecificAdminCharges { CustomerId = group.FirstOrDefault().CustomerId, CustomerName = group.FirstOrDefault().CustomerName, Charges = group.Select(subGroup => new AdminChargesTypes { AdminChargeId = subGroup.AdminChargeId, Amount = subGroup.Amount, ChargeType = subGroup.ChargeType, CreatedBy = subGroup.CreatedBy, CreatedOn = subGroup.CreatedOn, Key = subGroup.Key, Value = subGroup.Value }).ToList() }).FirstOrDefault(); return(charge); } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); return(null); } }
public FrayteResult SaveCustomerCharge(FrayteCustomerSpecificAdminCharges charge) { FrayteResult result = new FrayteResult(); try { AdminCharge adminCharge; foreach (var item in charge.Charges) { if (item.AdminChargeId == 0) { adminCharge = new AdminCharge(); adminCharge.Value = item.Amount; adminCharge.CustomerId = charge.CustomerId; adminCharge.CreatedOnUtc = DateTime.UtcNow; adminCharge.IsActive = true; adminCharge.Name = item.Value; adminCharge.ShortName = item.Key; adminCharge.OperationZoneId = UtilityRepository.GetOperationZone().OperationZoneId; adminCharge.ChargeType = item.ChargeType; adminCharge.CreatedBy = item.CreatedBy; adminCharge.CurrencyCode = "GBP";// item.CurrencyCode; dbcontext.AdminCharges.Add(adminCharge); dbcontext.SaveChanges(); } else { adminCharge = dbcontext.AdminCharges.Find(item.AdminChargeId); adminCharge.Value = item.Amount; adminCharge.UpdatedOnUtc = DateTime.UtcNow; adminCharge.UpdatedBy = item.CreatedBy; dbcontext.SaveChanges(); } } result.Status = true; } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); result.Status = false; } return(result); }