public AffairHeadersResponse Post(AffairHeaders request) { if (request.AffairHeader.Id > 0) { Bm2s.Data.Common.BLL.Parameter.AffairHeader item = Datas.Instance.DataStorage.AffairHeaders[request.AffairHeader.Id]; item.AffairId = request.AffairHeader.Affair.Id; item.HeaderId = request.AffairHeader.Header.Id; Datas.Instance.DataStorage.AffairHeaders[request.AffairHeader.Id] = item; } else { Bm2s.Data.Common.BLL.Parameter.AffairHeader item = new Data.Common.BLL.Parameter.AffairHeader() { AffairId = request.AffairHeader.Affair.Id, HeaderId = request.AffairHeader.Header.Id }; Datas.Instance.DataStorage.AffairHeaders.Add(item); request.AffairHeader.Id = item.Id; } AffairHeadersResponse response = new AffairHeadersResponse(); response.AffairHeaders.Add(request.AffairHeader); return response; }
public AffairHeadersResponse Delete(AffairHeaders request) { Bm2s.Data.Common.BLL.Parameter.AffairHeader item = Datas.Instance.DataStorage.AffairHeaders[request.AffairHeader.Id]; Datas.Instance.DataStorage.AffairHeaders.Remove(item); AffairHeadersResponse response = new AffairHeadersResponse(); response.AffairHeaders.Add(request.AffairHeader); return response; }
public AffairHeadersResponse Get(AffairHeaders request) { AffairHeadersResponse response = new AffairHeadersResponse(); List<Bm2s.Data.Common.BLL.Parameter.AffairHeader> items = new List<Data.Common.BLL.Parameter.AffairHeader>(); if (!request.Ids.Any()) { items.AddRange(Datas.Instance.DataStorage.AffairHeaders.Where(item => (request.AffairId == 0 || item.AffairId == request.AffairId) && (request.HeaderId == 0 || item.HeaderId == request.HeaderId) )); } else { items.AddRange(Datas.Instance.DataStorage.AffairHeaders.Where(item => request.Ids.Contains(item.Id))); } var collection = (from item in items select new Bm2s.Poco.Common.Parameter.AffairHeader() { Affair = new AffairsService().Get(new Affairs() { Ids = new List<int>() { item.AffairId } }).Affairs.FirstOrDefault(), Header = new HeadersService().Get(new Headers() { Ids = new List<int>() { item.HeaderId } }).Headers.FirstOrDefault(), Id = item.Id }).AsQueryable().OrderBy(request.Order, !request.DescendingOrder); response.ItemsCount = collection.Count(); if (request.PageSize > 0) { response.AffairHeaders.AddRange(collection.Skip((request.CurrentPage - 1) * request.PageSize).Take(request.PageSize)); } else { response.AffairHeaders.AddRange(collection); } try { response.PagesCount = collection.Count() / response.AffairHeaders.Count + (collection.Count() % response.AffairHeaders.Count > 0 ? 1 : 0); } catch { response.PagesCount = 1; } return response; }