public HeadersResponse Get(Headers request) { HeadersResponse response = new HeadersResponse(); List<Bm2s.Data.Common.BLL.Trade.Header> items = new List<Data.Common.BLL.Trade.Header>(); if (!request.Ids.Any()) { items.AddRange(Datas.Instance.DataStorage.Headers.Where(item => (request.ActivityId == 0 || item.ActivityId == request.ActivityId) && (!request.Date.HasValue || (request.Date >= item.Date && (!item.EndingDate.HasValue || request.Date < item.EndingDate.Value))) && (string.IsNullOrWhiteSpace(request.Description) || item.Description.ToLower().Contains(request.Description.ToLower())) && (request.HeaderStatusId == 0 || item.HeaderStatusId == request.HeaderStatusId) && (!request.IsSell || item.IsSell) && (!request.IsPurchase || item.IsPurchase) && (string.IsNullOrWhiteSpace(request.Reference) || item.Reference.ToLower().Contains(request.Reference.ToLower())) && (request.UserId == 0 || item.UserId == request.UserId) )); } else { items.AddRange(Datas.Instance.DataStorage.Headers.Where(item => request.Ids.Contains(item.Id))); } var collection = (from item in items select new Bm2s.Poco.Common.Trade.Header() { Activity = new ActivitiesService().Get(new Activities() { Ids = new List<int>() { item.ActivityId } }).Activities.FirstOrDefault(), Date = item.Date, DeliveryObservation = item.DeliveryObservation, Description = item.Description, EndingDate = item.EndingDate, FooterDiscount = Convert.ToDecimal(item.FooterDiscount), HeaderStatus = new HeaderStatusesService().Get(new HeaderStatuses() { Ids = new List<int>() { item.HeaderStatusId } }).HeaderStatuses.FirstOrDefault(), Id = item.Id, IsPurchase = item.IsPurchase, IsSell = item.IsSell, Reference = item.Reference, User = new UsersService().Get(new Users() { Ids = new List<int>() { item.UserId } }).Users.FirstOrDefault() }).AsQueryable().OrderBy(request.Order, !request.DescendingOrder); response.ItemsCount = collection.Count(); if (request.PageSize > 0) { response.Headers.AddRange(collection.Skip((request.CurrentPage - 1) * request.PageSize).Take(request.PageSize)); } else { response.Headers.AddRange(collection); } try { response.PagesCount = collection.Count() / response.Headers.Count + (collection.Count() % response.Headers.Count > 0 ? 1 : 0); } catch { response.PagesCount = 1; } return response; }
public HeadersResponse Delete(Headers request) { Bm2s.Data.Common.BLL.Trade.Header item = Datas.Instance.DataStorage.Headers[request.Header.Id]; item.EndingDate = DateTime.Now; Datas.Instance.DataStorage.Headers[item.Id] = item; HeadersResponse response = new HeadersResponse(); response.Headers.Add(request.Header); return response; }
public void Post() { this.Response = this.ConnectorHelper.Post(this.Request); this.IsFilled = true; }
public void Delete() { this.Response = this.ConnectorHelper.Delete(this.Request); this.IsFilled = true; }
public HeadersResponse Post(Headers request) { if (request.Header.Id > 0) { Bm2s.Data.Common.BLL.Trade.Header item = Datas.Instance.DataStorage.Headers[request.Header.Id]; item.ActivityId = request.Header.Activity.Id; item.Date = request.Header.Date; item.DeliveryObservation = request.Header.DeliveryObservation; item.Description = request.Header.Description; item.EndingDate = request.Header.EndingDate; item.FooterDiscount = Convert.ToDouble(request.Header.FooterDiscount); item.HeaderStatusId = request.Header.HeaderStatus.Id; item.IsPurchase = request.Header.IsPurchase; item.IsSell = request.Header.IsSell; item.Reference = request.Header.Reference; item.UserId = request.Header.User.Id; Datas.Instance.DataStorage.Headers[request.Header.Id] = item; } else { Bm2s.Data.Common.BLL.Trade.Header item = new Data.Common.BLL.Trade.Header() { ActivityId = request.Header.Activity.Id, Date = request.Header.Date, DeliveryObservation = request.Header.DeliveryObservation, Description = request.Header.Description, EndingDate = request.Header.EndingDate, FooterDiscount = Convert.ToDouble(request.Header.FooterDiscount), HeaderStatusId = request.Header.HeaderStatus.Id, IsPurchase = request.Header.IsPurchase, IsSell = request.Header.IsSell, Reference = request.Header.Reference, UserId = request.Header.User.Id }; Datas.Instance.DataStorage.Headers.Add(item); request.Header.Id = item.Id; } HeadersResponse response = new HeadersResponse(); response.Headers.Add(request.Header); return response; }