public ActionResult PopulateSelectList(string pianoMake) { try { Guid id = Guid.Parse(pianoMake); var list = Db.PianoSize.Where(x => x.PianoTypeId == id).ToList(). Select(x => new { id = x.Id, width = PianoSizeConversion.GetFeetInches(x.Width), }); return(Json(new { key = true, list = list }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { key = false }, JsonRequestBehavior.AllowGet)); } }
public ActionResult InitializePianoInventory([ModelBinder(typeof(DataTablesBinder))] IDataTablesRequest requestModel, string WareHouse, string Client) { if (WareHouse == string.Empty && Client == string.Empty) { return(Json(new DataTablesResponse (requestModel.Draw, Enumerable.Empty <Piano>(), 0, 0), JsonRequestBehavior.AllowGet)); } IQueryable <Piano> Pianos = Db.Pianos; if (WareHouse != string.Empty) { Guid id = Guid.Parse(WareHouse); Pianos = Pianos. Where(x => x.WarehouseId == id); } if (Client != string.Empty) { Guid id = Guid.Parse(Client); Pianos = Pianos. Where(x => x.ClientId == id); } Pianos = Pianos. Include(x => x.PianoMake). Include(x => x.PianoSize). Include(x => x.PianoType). Include(x => x.Client); var totalCount = Pianos.Count(); #region Filtering // Apply filters for searching if (requestModel.Search.Value != string.Empty) { var value = requestModel.Search.Value.Trim(); Pianos = Pianos.AsEnumerable(). Where(p => p.PianoType.Type.Contains(value) || p.PianoMake.Name.Contains(value) || p.SerialNumber.Contains(value) || p.Model.Contains(value) || p.Client.Name.Contains(value) || PianoSizeConversion.GetFeetInches(p.PianoSize.Width).Contains(value) ).AsQueryable(); } var filteredCount = Pianos.Count(); #endregion Filtering #region Sorting // Sorting var sortedColumns = requestModel.Columns.GetSortedColumns(); var orderByString = String.Empty; if (sortedColumns.Count() > 0) { foreach (var column in sortedColumns) { if (column.Data == "Type") { Pianos = column.SortDirection.ToString() == "Ascendant" ? Pianos.OrderBy(x => x.PianoType.Type) : Pianos.OrderByDescending(x => x.PianoType.Type); } if (column.Data == "Size") { Pianos = column.SortDirection.ToString() == "Ascendant" ? Pianos.OrderBy(x => x.PianoSize.Width) : Pianos.OrderByDescending(x => x.PianoSize.Width); } if (column.Data == "Make") { Pianos = column.SortDirection.ToString() == "Ascendant" ? Pianos.OrderBy(x => x.PianoMake.Name) : Pianos.OrderByDescending(x => x.PianoMake.Name); } if (column.Data == "Model") { Pianos = column.SortDirection.ToString() == "Ascendant" ? Pianos.OrderBy(x => x.Model) : Pianos.OrderByDescending(x => x.Model); } if (column.Data == "IsBench") { Pianos = column.SortDirection.ToString() == "Ascendant" ? Pianos.OrderBy(x => x.IsBench) : Pianos.OrderByDescending(x => x.IsBench); } if (column.Data == "IsPlayer") { Pianos = column.SortDirection.ToString() == "Ascendant" ? Pianos.OrderBy(x => x.IsPlayer) : Pianos.OrderByDescending(x => x.IsPlayer); } if (column.Data == "IsBoxed") { Pianos = column.SortDirection.ToString() == "Ascendant" ? Pianos.OrderBy(x => x.IsBoxed) : Pianos.OrderByDescending(x => x.IsBoxed); } if (column.Data == "Name") { Pianos = column.SortDirection.ToString() == "Ascendant" ? Pianos.OrderBy(x => x.Client.Name) : Pianos.OrderByDescending(x => x.Client.Name); } if (column.Data == "SerialNumber") { Pianos = column.SortDirection.ToString() == "Ascendant" ? Pianos.OrderBy(x => x.SerialNumber) : Pianos.OrderByDescending(x => x.SerialNumber); } } orderByString = "Ordered"; } if (orderByString == string.Empty) { Pianos = Pianos.OrderBy((x => x.PianoType.Type)); } #endregion Sorting // Paging if (requestModel.Length != -1) { Pianos = Pianos.Skip(requestModel.Start).Take(requestModel.Length); } var result = Pianos. ToList() .Select(x => new { Type = x.PianoType == null ? "No Data" : x.PianoType.Type, Size = x.PianoSize == null ? "No Data" : PianoSizeConversion.GetFeetInches(x.PianoSize.Width), Make = x.PianoMake == null ? "No Data" : x.PianoMake.Name, Model = x.Model, SerialNumber = x.SerialNumber, IsBench = x.IsBench ? "Yes" : "No", IsPlayer = x.IsPlayer ? "Yes" : "No", IsBoxed = x.IsBoxed ? "Yes" : "No", Name = x.Client == null ? "Not Data" : x.Client.Name }); return(Json(new DataTablesResponse (requestModel.Draw, result, filteredCount, totalCount), JsonRequestBehavior.AllowGet)); }
public ActionResult SendQoute(OrderVm orderVm) { try { String subject = string.Format(@"Order Qoute"); StringBuilder body = new StringBuilder(); body.AppendFormat(@"Please find the detailed qoute for order # {0} <br/><br/>", orderVm.OrderNumber); body.AppendFormat(@"Pick Up Address : {0} <br/><br/>", orderVm.PickupAddress.ToStringWithStairTurns); body.AppendFormat(@"Delivery Address : {0} <br/><br/>", orderVm.DeliveryAddress.ToStringWithStairTurns); body.AppendFormat(@"Units : <br/>"); foreach (var item in orderVm.Pianos) { body.AppendFormat(@"Bench? : {0} ", item.IsBench ? "Yes" : "No"); body.AppendFormat(@"Player? : {0} <br/>", item.IsPlayer ? "Yes" : "No"); body.AppendFormat(@"Boxed? : {0} ", item.IsBoxed ? "Yes" : "No"); body.AppendFormat(@"Serial Number : {0} ", item.SerialNumber); body.AppendFormat(@"Category : {0} ", ((PianoCategoryTypeEnum)(int.Parse(item.PianoCategoryType))).ToString()); body.AppendFormat(@"Make : {0} ", string.IsNullOrEmpty(item.PianoMake) ? "N/A" : Db.PianoMake.Where(x => x.Id.ToString() == item.PianoMake).FirstOrDefault().Name); body.AppendFormat(@"Model : {0} <br/>", item.PianoModel); body.AppendFormat(@"Size : {0} ", string.IsNullOrEmpty(item.PianoSize) ? "N/A" : PianoSizeConversion.GetFeetInches(Db.PianoSize.Where(x => x.Id.ToString() == item.PianoSize).FirstOrDefault().Width)); body.AppendFormat(@"Type : {0} ", string.IsNullOrEmpty(item.PianoTypeId) ? "N/A" : Db.PianoTypes.Where(x => x.Id.ToString() == item.PianoTypeId).FirstOrDefault().Type); body.AppendFormat(@"Finish : {0} <br/>", string.IsNullOrEmpty(item.PianoFinish) ? "N/A" : Db.PianoFinish.Where(x => x.Id.ToString() == item.PianoFinish).FirstOrDefault().Name); body.AppendFormat(@"Miscellaneous : {0} <br/><br/>", item.Notes); } body.AppendFormat(@"Charges : <br/>"); foreach (var item in orderVm.Charges) { body.AppendFormat(@"Type : {0} ", Db.PianoCharges.Where(x => x.Id.ToString() == item.ChargesCode).FirstOrDefault().Details); body.AppendFormat(@"Amount : {0} <br/>", item.Amount); } EmailHelper.SendEmail(orderVm.CallerEmail, subject, body.ToString()); return(Json(new { key = true }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { key = false }, JsonRequestBehavior.AllowGet)); } }
public ActionResult InitializeInvoiceGrid([ModelBinder(typeof(DataTablesBinder))] IDataTablesRequest requestModel, string Client, string StartDate, string EndDate) { if (Client == string.Empty || StartDate == null || EndDate == null) { return(Json(new DataTablesResponse (requestModel.Draw, Enumerable.Empty <Piano>(), 0, 0), JsonRequestBehavior.AllowGet)); } IEnumerable <Order> Orders = GetOrders(Client, StartDate, EndDate); List <Piano> Pianos = new List <Piano>(); foreach (var item in Orders) { List <Piano> PianosNew = item.Pianos.ToList(); Pianos.AddRange(PianosNew); } var totalCount = Pianos.Count(); #region Filtering // Apply filters for searching if (requestModel.Search.Value != string.Empty) { var value = requestModel.Search.Value.Trim(); Pianos = Pianos.Where(p => p.PianoType != null ? p.PianoType.Type.Contains(value) : p.SerialNumber.Contains(value) || p.PianoMake != null ? p.PianoMake.Name.Contains(value) : p.SerialNumber.Contains(value) || p.SerialNumber.Contains(value) || p.Model.Contains(value) || p.PianoMake != null ? p.Client.Name.Contains(value) : p.SerialNumber.Contains(value) || p.PianoSize != null ? PianoSizeConversion.GetFeetInches(p.PianoSize.Width).Contains(value) : p.SerialNumber.Contains(value) ).ToList(); } var filteredCount = Pianos.Count(); #endregion Filtering #region Sorting // Sorting var sortedColumns = requestModel.Columns.GetSortedColumns(); var orderByString = String.Empty; if (sortedColumns.Count() > 0) { foreach (var column in sortedColumns) { if (column.Data == "Type") { Pianos = column.SortDirection.ToString() == "Ascendant" ? Pianos.OrderBy(x => x.PianoType == null ? x.SerialNumber : x.PianoType.Type).ToList() : Pianos.OrderByDescending(x => x.PianoType == null ? x.SerialNumber : x.PianoType.Type).ToList(); } if (column.Data == "Size") { Pianos = column.SortDirection.ToString() == "Ascendant" ? Pianos.OrderBy(x => x.PianoSize.Width).ToList() : Pianos.OrderByDescending(x => x.PianoSize.Width).ToList(); } if (column.Data == "Make") { Pianos = column.SortDirection.ToString() == "Ascendant" ? Pianos.OrderBy(x => x.PianoMake.Name).ToList() : Pianos.OrderByDescending(x => x.PianoMake.Name).ToList(); } if (column.Data == "Model") { Pianos = column.SortDirection.ToString() == "Ascendant" ? Pianos.OrderBy(x => x.Model).ToList() : Pianos.OrderByDescending(x => x.Model).ToList(); } if (column.Data == "IsBench") { Pianos = column.SortDirection.ToString() == "Ascendant" ? Pianos.OrderBy(x => x.IsBench).ToList() : Pianos.OrderByDescending(x => x.IsBench).ToList(); } if (column.Data == "IsPlayer") { Pianos = column.SortDirection.ToString() == "Ascendant" ? Pianos.OrderBy(x => x.IsPlayer).ToList() : Pianos.OrderByDescending(x => x.IsPlayer).ToList(); } if (column.Data == "IsBoxed") { Pianos = column.SortDirection.ToString() == "Ascendant" ? Pianos.OrderBy(x => x.IsBoxed).ToList() : Pianos.OrderByDescending(x => x.IsBoxed).ToList(); } if (column.Data == "Name") { Pianos = column.SortDirection.ToString() == "Ascendant" ? Pianos.OrderBy(x => x.Client.Name).ToList() : Pianos.OrderByDescending(x => x.Client.Name).ToList(); } if (column.Data == "SerialNumber") { Pianos = column.SortDirection.ToString() == "Ascendant" ? Pianos.OrderBy(x => x.SerialNumber).ToList() : Pianos.OrderByDescending(x => x.SerialNumber).ToList(); } } orderByString = "Ordered"; } if (orderByString == string.Empty) { Pianos = Pianos.OrderBy((x => x.Id)).ToList(); } #endregion Sorting // Paging if (requestModel.Length != -1) { Pianos = Pianos.Skip(requestModel.Start).Take(requestModel.Length).ToList(); } var result = Pianos .Select(x => new { Type = x.PianoType == null ? "No Data" : x.PianoType.Type, Size = x.PianoSize == null ? "No Data" : PianoSizeConversion.GetFeetInches(x.PianoSize.Width), Make = x.PianoMake == null ? "No Data" : x.PianoMake.Name, Model = x.Model, SerialNumber = x.SerialNumber, IsBench = x.IsBench ? "Yes" : "No", IsPlayer = x.IsPlayer ? "Yes" : "No", IsBoxed = x.IsBoxed ? "Yes" : "No", Name = x.Client == null ? "No Data" : x.Client.Name }); return(Json(new DataTablesResponse (requestModel.Draw, result, totalCount, totalCount), JsonRequestBehavior.AllowGet)); }