Ejemplo n.º 1
0
        public HttpResponseMessage GetAllSuccessBaskets()
        {
            var baskets = _basketRepository.FindAll(z => z.DateSuccess != null).OrderByDescending(z => z.DateSuccess).ToList();

            if (baskets.Count == 0)
            {
                return(ErrorResult("no baskets"));
            }
            var result = baskets.Select(basket => new BasketData
            {
                Basket = basket, User = _userRepository.GetFirstOrDefault(z => z.Id == basket.UserId)
            }).ToList();

            return(SuccessResult(result));
        }
Ejemplo n.º 2
0
        public HttpResponseMessage Export()
        {
            var allExports = _export.All().OrderBy(z => z.Date).ToList();
            var number     = allExports.Count != 0 ? allExports[allExports.Count - 1].Number + 1 : 1;
            var orders     = allExports.Count != 0 ? _basket.FindAll(z => z.DateSuccess != null && z.DateSuccess > allExports[allExports.Count - 1].Date) : _basket.FindAll(z => z.DateSuccess != null);

            if (orders.Count == 0)
            {
                return(ErrorResult("no items"));
            }

            var settings = new XmlWriterSettings {
                Indent = true, Encoding = Encoding.UTF8
            };
            var xmlDoc = HttpContext.Current.Request.PhysicalApplicationPath + "app\\export\\order_export_" + number + ".xml";

            using (var writer = XmlWriter.Create(xmlDoc, settings))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("orders");
                foreach (var order in orders)
                {
                    var user = _user.GetFirstOrDefault(z => z.Id == order.UserId);
                    writer.WriteStartElement("order");
                    writer.WriteElementString("userName", user.Name + " " + user.Surname);
                    writer.WriteElementString("publicId", order.PublicId);
                    writer.WriteElementString("dateCreate", Convert.ToString(order.DateCreate));
                    writer.WriteElementString("dateSuccess", Convert.ToString(order.DateSuccess));
                    writer.WriteElementString("dateUpdate", Convert.ToString(order.DateUpdate));
                    writer.WriteElementString("total", Convert.ToString(order.Total));
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
            _export.CreateItem(new Export
            {
                Date   = DateTime.Now,
                Id     = Guid.NewGuid(),
                Number = number
            });

            var result = new HttpResponseMessage(HttpStatusCode.OK);
            var stream = new FileStream(xmlDoc, FileMode.Open);

            result.Content = new StreamContent(stream);
            result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");

            return(SuccessResult(result));
        }