コード例 #1
0
        public async Task <Bid> Put(int bidId, EditBidModel model)
        {
            var bidModel = GetQuery().Include("BidDetails").Include("BidDetails.FormField").FirstOrDefault(x => x.Id == bidId);

            if (bidModel == null)
            {
                throw new NotFoundException();
            }

            var bid = _mapper.Map <Bid>(bidModel);

            for (int i = 0; i < bid.BidDetails.Count; i++)
            {
                var newValue = model.BidDetails.Where(a => a.Id == bid.BidDetails[i].Id).FirstOrDefault();

                if (newValue != null && newValue.FormFieldId == 10 && bid.BidDetails[i].Value != newValue.Value)
                {
                    model.BidDetails[i].Value = UploadImageHelper.SaveImage(model.BidDetails[i].Value, "Bids");
                }
                else if (newValue != null && newValue.FormFieldId == 8 && bid.BidDetails[i].Value != newValue.Value)
                {
                    model.BidDetails[i].Value = UploadImageHelper.SavePdf(model.BidDetails[i].Value, "Bids");
                }
                else
                {
                    bid.BidDetails[i].Value = newValue == null ? "" : newValue.Value;
                }
            }

            var deletedItems = bid.BidDetails.Where(a => !model.BidDetails.Any(x => a.Id == x.Id)).Select(a => a.Id).ToArray();

            foreach (var item in deletedItems)
            {
                var reqDetail = bid.BidDetails.Where(a => a.Id == item).First();
                bid.BidDetails.Remove(reqDetail);
            }

            var addedItems = model.BidDetails.Where(a => a.Id == 0);

            foreach (var item in addedItems)
            {
                bid.BidDetails.Add(new  BidDetail
                {
                    BidId       = bidId,
                    FormFieldId = item.FormFieldId,
                    Value       = item.Value
                });
            }

            await _uow.CommitAsync();

            return(bid);
        }
コード例 #2
0
        public async Task <Request> Put(int requestId, EditRequestModel model)
        {
            var requestModel = GetQuery().Include("RequestDetails").Include("RequestDetails.FormField").FirstOrDefault(x => x.Id == requestId);

            if (requestModel == null)
            {
                throw new NotFoundException();
            }

            var request = _mapper.Map <Request>(requestModel);

            for (int i = 0; i < request.RequestDetails.Count; i++)
            {
                var newValue = model.RequestDetails.Where(a => a.Id == request.RequestDetails[i].Id).FirstOrDefault();

                if (newValue != null && newValue.FormFieldId == 10 && request.RequestDetails[i].Value != newValue.Value)
                {
                    model.RequestDetails[i].Value = UploadImageHelper.SaveImage(model.RequestDetails[i].Value, "Requests");
                }
                else if (newValue != null && newValue.FormFieldId == 8 && request.RequestDetails[i].Value != newValue.Value)
                {
                    model.RequestDetails[i].Value = UploadImageHelper.SavePdf(model.RequestDetails[i].Value, "Requests");
                }
                else
                {
                    request.RequestDetails[i].Value = newValue == null ? "" : newValue.Value;
                }
            }

            var deletedItems = request.RequestDetails.Where(a => !model.RequestDetails.Any(x => a.Id == x.Id)).Select(a => a.Id).ToArray();

            foreach (var item in deletedItems)
            {
                var reqDetail = request.RequestDetails.Where(a => a.Id == item).First();
                request.RequestDetails.Remove(reqDetail);
            }

            var addedItems = model.RequestDetails.Where(a => a.Id == 0);

            foreach (var item in addedItems)
            {
                request.RequestDetails.Add(new RequestDetail
                {
                    RequestId   = requestId,
                    FormFieldId = item.FormFieldId,
                    Value       = item.Value
                });
            }

            await _uow.CommitAsync();

            return(request);
        }
コード例 #3
0
        public async Task <Bid> Create(CreateBidModel model)
        {
            for (int i = 0; i < model.BidDetails.Count; i++)
            {
                if (model.BidDetails[i].FieldTypeId == 10)
                {
                    model.BidDetails[i].Value = UploadImageHelper.SaveImage(model.BidDetails[i].Value, "Bids");
                }
                else if (model.BidDetails[i].FieldTypeId == 8)
                {
                    model.BidDetails[i].Value = UploadImageHelper.SavePdf(model.BidDetails[i].Value, "Bids");
                }
            }

            var request = _mapper.Map <Bid>(model);

            _uow.Add(request);
            await _uow.CommitAsync();

            return(request);
        }
コード例 #4
0
        public async Task <Request> Create(CreateRequestModel model)
        {
            for (int i = 0; i < model.RequestDetails.Count; i++)
            {
                if (model.RequestDetails[i].FieldTypeId == 10)
                {
                    model.RequestDetails[i].Value = UploadImageHelper.SaveImage(model.RequestDetails[i].Value, "Requests");
                }
                else if (model.RequestDetails[i].FieldTypeId == 8)
                {
                    model.RequestDetails[i].Value = UploadImageHelper.SavePdf(model.RequestDetails[i].Value, "Requests");
                }
            }

            var request = _mapper.Map <Request>(model);

            request.StatusId = (int)RequestStatus.Opened;
            _uow.Add(request);
            await _uow.CommitAsync();

            return(request);
        }