public ActionResult CSVExport([DataSourceRequest] DataSourceRequest request)
        {
            Expression <Func <Order, bool> > predicate = x => true
                                                         //  && x.OrderStatus != OrderStatus.New
                                                         // && x.OrderStatus != OrderStatus.Canceled
                                                         //  && x.OrderStatus != OrderStatus.Rejected
            ;

            if (request.Filters != null)
            {
                predicate = GetPredicate(predicate, request.Filters);
            }
            var items = _db.Orders.Where(predicate).Select(x => new PaymentReportItemModel()
            {
                ID            = x.ID,
                ShopID        = x.ShopID,
                IsPaidUp      = x.IsPaidUp,
                OrderID       = x.ID,
                Date          = x.CreateOn,
                PaymentMethod = x.PaymentMethod,
                Total         = x.Total
            }).ToList();

            foreach (var item in items)
            {
                item.Total            = item.Cash + item.Card;
                item.TotalStr         = ShoppingService.FormatPrice(item.Total);
                item.PayedTo          = item.Card > 0 ? PayedToType.ToAdmin : PayedToType.ToShop;
                item.PayedToStr       = RP.T("Enums." + item.PayedTo.ToString()).ToString();
                item.PaymentMethodStr = RP.T("Enums." + item.PaymentMethod.ToString()).ToString();
                item.DateStr          = item.Date.HasValue ? item.Date.Value.ToString("dd/MM HH:mm") : "";
            }
            // var items = _db.AbstractPages.Where(r => r.Visible == true).OrderBy(r => r.Title).ToList();
            MemoryStream output = new MemoryStream();
            StreamWriter writer = new StreamWriter(output, Encoding.UTF8);

            writer.Write(RP.M("PaymentReportItemModel", "OrderID") + ",");
            writer.Write(RP.M("PaymentReportItemModel", "Date") + ",");
            writer.Write(RP.M("PaymentReportItemModel", "Total") + ",");
            writer.Write(RP.M("PaymentReportItemModel", "PaymentMethod") + ",");
            writer.Write(RP.M("PaymentReportItemModel", "PayedTo"));
            writer.WriteLine();
            var csvQuote = "\"";

            foreach (var item in items)
            {
                writer.Write(item.OrderID); writer.Write(",\"");
                writer.Write(item.DateStr.Replace(csvQuote, csvQuote + csvQuote)); writer.Write("\",\"");
                writer.Write(item.TotalStr.Replace(csvQuote, csvQuote + csvQuote)); writer.Write("\",\"");
                writer.Write(item.PaymentMethodStr.Replace(csvQuote, csvQuote + csvQuote)); writer.Write("\",\"");
                writer.Write(item.PayedToStr.Replace(csvQuote, csvQuote + csvQuote)); writer.Write("\"");
                writer.WriteLine();
            }
            writer.Flush();
            output.Position = 0;
            Encoding heb = Encoding.GetEncoding("windows-1255");

            return(File(heb.GetBytes(new StreamReader(output).ReadToEnd()), "text/csv", "PaymentReport_" + (DateTime.Now.ToString("dd/MM HH:mm")) + ".csv"));
        }
Example #2
0
        //private static UiResources ui = new UiResources(); // database class
        protected override ModelMetadata CreateMetadata(
            IEnumerable <Attribute> attributes,
            Type containerType,
            Func <object> modelAccessor,
            Type modelType,
            string propertyName)
        {
            ModelMetadata baseres = null;

            try
            {
                baseres = base.CreateMetadata
                              (attributes, containerType, modelAccessor, modelType, propertyName);
            }
            catch (Exception e)
            {
                baseres = base.CreateMetadata
                              (new List <Attribute>(), containerType, modelAccessor, modelType, propertyName);
            }
            string sKey           = string.Empty; //  ощощ мчбмъ дтшк щм displayname
            string tab            = string.Empty;
            string sLocalizedText = string.Empty; // ощъощ мчбм тшк оъешвн

            HttpContext.Current.Application.Lock();
            string keyType = "";

            if (containerType != null)
            {
                keyType = containerType.Name;
                if (containerType.BaseType != null && containerType.BaseType == typeof(AbstractPage))
                {
                    keyType = containerType.BaseType.Name;
                }
            }
            bool?  hideTab = null;
            string currole = null;

            if (HttpContext.Current != null)
            {
                var controller = HttpContext.Current.Items["controllerInstance"] as BaseController;
                if (controller != null)
                {
                    currole = controller.ViewBag.CurrentRole;
                }
            }
            if (containerType != null && propertyName != null)
            {
                var modelAttr = containerType.GetProperty(propertyName).GetCustomAttributes <ModelAttribute>()
                                .Where(x => x.Role == currole || x.Role == null).OrderByDescending(x => x.Role).ToList().FirstOrDefault();

                if (modelAttr != null)
                {
                    if (!hideTab.HasValue && !modelAttr.ShowInEdit && !modelAttr.Edit)
                    {
                        hideTab = true;
                    }
                }
            }
            foreach (var attr in attributes)
            {
                if (attr != null)
                {
                    string typeName   = attr.GetType().Name; // ощйв аъ сев дтшк мгевоа DisplayAttribute
                    string attrAppKey = string.Empty;

                    if (typeName.Equals("DisplayAttribute"))
                    {
                        sKey = ((DisplayAttribute)attr).Name;
                        var tabKey = ((DisplayAttribute)attr).Prompt;
                        //if (tabKey != null && tabKey.StartsWith("Tab"))
                        //{
                        //    tabKey = tabKey.Substring("Tab".Length);
                        //}


                        if (!string.IsNullOrEmpty(tabKey))
                        {
                            // attrAppKey = string.Format("{0}-{1}-{2}", containerType.Name, propertyName, typeName);

                            if (RP.Mbool(out tabKey, keyType, ((DisplayAttribute)attr).Prompt, "Prompt"))
                            {
                                // rewriteTab = true;
                                baseres.Watermark = tabKey;
                                //((DisplayAttribute)attr).ResourceType = null;
                            }
                            else
                            {
                                if (!string.IsNullOrEmpty(tabKey) && tabKey != baseres.Watermark)
                                {
                                    RP.Madd(keyType, tabKey, "Prompt", baseres.Watermark);
                                }
                            }
                        }
                    }
                    //else if (attr is ValidationAttribute)
                    //{
                    //    sKey = ((ValidationAttribute)attr).ErrorMessage;

                    //    if (!string.IsNullOrEmpty(sKey))
                    //    {
                    //        attrAppKey = string.Format("{0}-{1}-{2}", containerType.Name, propertyName, typeName);


                    //        ((ValidationAttribute)attr).ErrorMessage = sKey;
                    //    }
                    //}
                    else if (attr is ValidationAttribute)
                    {
                        sKey = ((ValidationAttribute)attr).ErrorMessage;

                        if (!string.IsNullOrEmpty(sKey))
                        {
                            attrAppKey = string.Format("{0}-{1}-{2}",
                                                       keyType, propertyName, typeName);
                            if (HttpContext.Current.Application[attrAppKey] == null)
                            {
                                HttpContext.Current.Application[attrAppKey] = sKey;
                            }
                            else
                            {
                                sKey = HttpContext.Current.Application[attrAppKey].ToString();
                            }

                            sLocalizedText = RP.T(sKey).ToString();
                            if (string.IsNullOrEmpty(sLocalizedText))
                            {
                                sLocalizedText = sKey;
                            }

                            ((ValidationAttribute)attr).ErrorMessage = sLocalizedText;
                        }
                    }
                }
            }


            if (!string.IsNullOrEmpty(sKey))
            {
                // attrAppKey = string.Format("{0}-{1}-{2}", containerType.Name, propertyName, typeName);

                if (RP.Mbool(out sKey, keyType, propertyName))
                {
                    // rewriteName = true;
                    baseres.DisplayName = sKey;
                    //((DisplayAttribute)attr).ResourceType = null;
                }
                // else
                // {

                if (!string.IsNullOrEmpty(sKey) &&
                    sKey != baseres.DisplayName
                    //&& ((DisplayAttribute)attr).Name != baseres.DisplayName //update if different
                    && sKey.Contains(".")) // update if it auto generated
                {
                    RP.Madd(keyType, propertyName, "", baseres.DisplayName);
                }

                // }
            }
            else if (containerType != null && keyType != null && propertyName != null)
            {
                baseres.DisplayName = RP.M(keyType, propertyName);
            }
            if (hideTab.HasValue && hideTab.Value && baseres.Watermark != null)
            {
                baseres.Watermark = null;
            }
            return(baseres);
        }
Example #3
0
 /// <summary>
 /// Localization Model Fields
 /// </summary>
 /// <param name="text"></param>
 /// <returns></returns>
 public string M(string model, string text)
 {
     return(RP.M(model, text));
 }
        public ActionResult SaveCell(int ID, string Field, string Value, string OrderNote)
        {
            //if(string.IsNullOrEmpty(OrderNote))
            //{
            //    return Json(new { result = "error", message = "Note required", value = Value });
            //}
            var order = _db.Orders.FirstOrDefault(x => x.ID == ID);

            if (order != null)
            {
                var property = order.GetType().GetProperty(Field);
                if (property != null)
                {
                    var oldValue = property.GetValue(order);
                    order.SetValueFromString(Field, Value);
                    var newValue    = property.GetValue(order);
                    var oldValueStr = oldValue.ToString();
                    var newValueStr = newValue.ToString();
                    if (property.PropertyType.Name == "Double")
                    {
                        oldValueStr = ((decimal)oldValue).ToString("0.00");
                        newValueStr = ((decimal)newValue).ToString("0.00");
                    }

                    if (Field != "Total" && Field != "TotalCash")
                    {
                        //fix totals
                        if (order.ShippingMethod == ShippingMethod.Manual)
                        {
                            order.ShipCost = 0;
                        }
                        order.Total = order.SubTotal + order.ShipCost + order.Fee - order.TotalDiscountAmount;
                    }

                    if (newValueStr != oldValueStr)
                    {
                        _db.SaveChanges();
                        //adding note
                        if (string.IsNullOrEmpty(OrderNote))
                        {
                            OrderNote = RP.S("Member.OrderNote.DefaultMessage");
                        }
                        var note = new OrderNote()
                        {
                            CreateDate = DateTime.Now,
                            Field      = RP.M("Order", Field),
                            OrderID    = order.ID,
                            Note       = OrderNote,
                            NewValue   = newValueStr,
                            OldValue   = oldValueStr
                        };
                        _db.OrderNotes.Add(note);
                        _db.SaveChanges();

                        return(Json(new { result = "ok", value = Value }));
                    }
                    return(Json(new { result = "error", message = "Value not changed", value = Value }));
                }
                return(Json(new { result = "error", message = "no property", value = Value }));
            }
            return(Json(new { result = "error", message = "not found", value = Value }));
        }