/// <summary> /// convert foundry invoice view model to domain /// </summary> /// <param name="model"></param> /// <returns></returns> public FoundryInvoice ConvertToDomain(FoundryInvoiceViewModel model) { FoundryInvoice foundryInvoice = new FoundryInvoice(); foundryInvoice.FoundryInvoiceId = model.FoundryInvoiceId; foundryInvoice.FoundryId = model.FoundryId; foundryInvoice.Number = model.InvoiceNumber; foundryInvoice.Amount = model.InvoiceAmount; foundryInvoice.ScheduledPaymentDate = model.ScheduledPaymentDate; foundryInvoice.ActualPaymentDate = model.ActualPaymentDate; foundryInvoice.Notes = model.Notes; foundryInvoice.AirFreight = model.AirFreight; foundryInvoice.HasBeenProcessed = model.HasBeenProcessed; var buckets = new List <Bucket>(); if (model.Buckets != null && model.Buckets.Count > 0) { foreach (var bucket in model.Buckets) { Bucket convertedModel = new BucketConverter().ConvertToDomain(bucket); buckets.Add(convertedModel); } } foundryInvoice.Buckets = buckets; return(foundryInvoice); }
/// <summary> /// convert foundry invoice to view model /// </summary> /// <param name="invoice"></param> /// <returns></returns> public FoundryInvoiceViewModel ConvertToView(FoundryInvoice invoice) { FoundryInvoiceViewModel model = new FoundryInvoiceViewModel(); var _foundryDynamicsRepository = new FoundryDynamicsRepository(); var _bucketRepository = new BucketRepository(); var dynamicsFoundry = _foundryDynamicsRepository.GetFoundry(invoice.FoundryId); var buckets = _bucketRepository.GetBuckets().Where(x => x.FoundryInvoiceId == invoice.FoundryInvoiceId).ToList(); model.FoundryInvoiceId = invoice.FoundryInvoiceId; model.BillOfLadingId = invoice.FoundryInvoiceId; model.InvoiceNumber = (!string.IsNullOrEmpty(invoice.Number)) ? invoice.Number : "N/A"; model.InvoiceAmount = invoice.Amount; model.ScheduledPaymentDate = (invoice.ScheduledPaymentDate != null) ? invoice.ScheduledPaymentDate : DateTime.MinValue; model.ScheduledPaymentDateStr = (invoice.ScheduledPaymentDate != null) ? invoice.ScheduledPaymentDate.Value.ToShortDateString() : "N/A"; model.ActualPaymentDate = (invoice.ActualPaymentDate != null) ? invoice.ActualPaymentDate : DateTime.MinValue;; model.ActualPaymentDateStr = (invoice.ActualPaymentDate != null) ? invoice.ActualPaymentDate.Value.ToShortDateString() : "N/A"; model.Notes = (!string.IsNullOrEmpty(invoice.Notes)) ? invoice.Notes : "N/A"; model.FoundryId = invoice.FoundryId; model.FoundryName = (dynamicsFoundry != null && !string.IsNullOrEmpty(dynamicsFoundry.VENDSHNM)) ? dynamicsFoundry.VENDSHNM : "N/A"; model.AirFreight = invoice.AirFreight; model.HasBeenProcessed = invoice.HasBeenProcessed; model.CreateDate = (invoice.CreatedDate != null) ? invoice.CreatedDate : DateTime.MinValue; model.CreateDateStr = (invoice.CreatedDate != null) ? invoice.CreatedDate.Value.ToShortDateString() : "N/A"; model.Buckets = new List <BucketViewModel>(); if (buckets != null && buckets.Count > 0) { foreach (var bucket in buckets) { BucketViewModel convertedModel = new BucketConverter().ConvertToView(bucket); model.Buckets.Add(convertedModel); } } if (_foundryDynamicsRepository != null) { _foundryDynamicsRepository.Dispose(); _foundryDynamicsRepository = null; } if (_bucketRepository != null) { _bucketRepository.Dispose(); _bucketRepository = null; } return(model); }
public JsonResult SearchFoundryInvoices(FoundryInvoiceViewModel model) { var foundryInvoices = new List <FoundryInvoiceViewModel>(); var tempInvoices = _foundryInvoiceRepository.GetFoundryInvoices(); if (tempInvoices != null && tempInvoices.Count > 0) { foreach (var tempInvoice in tempInvoices) { FoundryInvoiceViewModel convertedModel = new FoundryInvoiceConverter().ConvertToView(tempInvoice); foundryInvoices.Add(convertedModel); } } if (model.InvoiceNumber != null && model.InvoiceNumber != string.Empty) { foundryInvoices = foundryInvoices.Where(x => x.InvoiceNumber.ToLower() == model.InvoiceNumber.ToLower()).ToList(); } if (model.FoundryId != null && model.FoundryId != string.Empty && model.FoundryId != "--Select Foundry--") { foundryInvoices = foundryInvoices.Where(x => x.FoundryId.Replace(" ", string.Empty).ToLower() == model.FoundryId.Replace(" ", string.Empty).ToLower()).ToList(); } if (model.Unscheduled) { foundryInvoices = foundryInvoices.Where(x => x.ScheduledPaymentDate == null).ToList(); } else { if (model.FromDate != null && model.ToDate != null) { var fromDate = model.FromDate; var toDate = model.ToDate.AddDays(1); foundryInvoices = foundryInvoices.Where(x => x.ScheduledPaymentDate >= fromDate && x.ScheduledPaymentDate <= toDate).ToList(); } } model.FoundryInvoices = foundryInvoices.OrderBy(x => x.InvoiceNumber).ToList(); return(Json(model, JsonRequestBehavior.AllowGet)); }
public ActionResult FoundryInvoices() { var model = new FoundryInvoiceViewModel(); model.SelectableFoundries = _foundryDynamicsRepository.GetSelectableFoundries(); var defaultFoundry = new SelectListItem() { Text = "--Select Foundry--", Value = null }; model.SelectableFoundries.Insert(0, defaultFoundry); model.FromDateStr = DateTime.Now.ToShortDateString(); model.ToDateStr = DateTime.Now.ToShortDateString(); return(View(model)); }
public JsonResult UpdateFoundryInvoice(FoundryInvoiceViewModel model) { var operationResult = new OperationResult(); FoundryInvoice foundryInvoice = new FoundryInvoiceConverter().ConvertToDomain(model); operationResult = _foundryInvoiceRepository.UpdateFoundryInvoice(foundryInvoice); if (!operationResult.Success) { this.AddNotification(operationResult.Message, NotificationType.ERROR); } else { this.AddNotification(operationResult.Message, NotificationType.SUCCESS); } return(Json(operationResult, JsonRequestBehavior.AllowGet)); }