public ActionResult Create(HousingPropertyViewModel propertyVM) { var userId = User.Identity.GetUserId(); Order order = _unitOfWork.Orders.GetOrderFor(userId, propertyVM.OrderId, User.GetUserRole()); if (order == null || !order.HasHomeFinding) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); } HomeFindingProperty homeFindingProperty = new HomeFindingProperty(); // mapping wipes out the Id - this is hack to resolve that propertyVM.Id = homeFindingProperty.Id; propertyVM.CurrUser = User; _mapper.Map <HousingPropertyViewModel, HomeFindingProperty>(propertyVM, homeFindingProperty); HomeFinding homeFinding = order.HomeFinding; homeFinding.HomeFindingProperties.Add(homeFindingProperty); foreach (var postedFile in propertyVM.UploadedPhotos) { if (postedFile != null) { try { var storageId = _imageStore.SaveImage(postedFile.InputStream); var urlStr = _imageStore.UriFor(storageId).AbsoluteUri; var photo = new Photo(storageId, urlStr); homeFindingProperty.Property.Photos.Add(photo); } catch (Exception e) { return(new HttpStatusCodeResult(HttpStatusCode.ServiceUnavailable)); } } } try { _unitOfWork.Complete(); } catch (Exception e) { return(new HttpStatusCodeResult(HttpStatusCode.ServiceUnavailable)); } return(new HttpStatusCodeResult(HttpStatusCode.Created)); }
private Order BuildOrder(bool emptyProperties = true) { Order order = OrderBuilder.New().First(); order.Transferee = transferee; order.ProgramManager = pm; order.Consultant = dsc; HomeFinding homeFinding = HomeFindingBuilder.New(); if (emptyProperties) { // The builder makes a single property, but we want it empty homeFinding.HomeFindingProperties = new Collection <HomeFindingProperty>(); } order.HomeFinding = homeFinding; return(order); }
/*-------------------------------------------------*/ private Order BuildOrder(bool emptyProperties = true) { Order order = OrderBuilder.New().First(); order.Transferee = transferee; order.ProgramManager = pm; order.Consultant = dsc; order.ServiceFlag = (int)ServiceCategory.AccompaniedHomeFinding; //Has homefinding service. HomeFinding homeFinding = HomeFindingBuilder.New(); if (emptyProperties) { // The builder makes a single property, but we want it empty homeFinding.HomeFindingProperties = new Collection <HomeFindingProperty>(); } order.HomeFinding = homeFinding; return(order); }
public void GetUpcomingHomeFindingPropertiesByOrderId_ReturnsOnlyFutureProperties() { HomeFinding homeFinding = HomeFindingBuilder.New(); HomeFindingProperty yesterdayHFP = HomeFindingPropertiesBuilder.New().First(); yesterdayHFP.ViewingDate = DateTime.Now.AddDays(-1); yesterdayHFP.HomeFinding = homeFinding; HomeFindingProperty tomorrowHFP = HomeFindingPropertiesBuilder.New().First(); tomorrowHFP.ViewingDate = DateTime.Now.AddDays(1); tomorrowHFP.HomeFinding = homeFinding; HomeFindingProperty nextWeekHFP = HomeFindingPropertiesBuilder.New().First(); nextWeekHFP.ViewingDate = DateTime.Now.AddDays(7); nextWeekHFP.HomeFinding = homeFinding; HomeFindingProperty noShowingHFP = HomeFindingPropertiesBuilder.New().First(); noShowingHFP.ViewingDate = null; noShowingHFP.HomeFinding = homeFinding; var hfps = new[] { yesterdayHFP, tomorrowHFP, nextWeekHFP, noShowingHFP }; SetupRepositoryWithSource(hfps); // Act IEnumerable <HomeFindingProperty> upcomingViewings = _homeFindingPropertiesRepository.GetUpcomingHomeFindingPropertiesByHomeFindingId(homeFinding.Id); // Assert upcomingViewings.Count().Should().Be(2); upcomingViewings.Should().NotContain(yesterdayHFP); upcomingViewings.Should().NotContain(noShowingHFP); upcomingViewings.Should().Contain(tomorrowHFP); upcomingViewings.Should().Contain(nextWeekHFP); }
public void ImportOrder(OrderDto orderDto) { var order = _unitOfWork.Orders.GetOrderByTrackingId(orderDto.TrackingId); // Will error if no consultant is found, expected behaivor, an order doesn't make sense without a consultant Consultant consultant = _unitOfWork.Consultants.GetConsultantBySeContactUid(orderDto.Consultant.SeContactUid); var consultantId = consultant.Id; var transferee = _unitOfWork.Transferees.GetTransfereeByEmail(orderDto.Transferee.Email); var programManagerId = _unitOfWork.Managers.GetManagerBySeContactUid(orderDto.ProgramManager.SeContactUid).Id; var IsNew = false; if (order == null) { order = _mapper.Map <OrderDto, Order>(orderDto); if (transferee == null) { transferee = _mapper.Map <TransfereeDto, Transferee>(orderDto.Transferee); transferee.InviteStatus = InviteStatus.NotYetInvited; _unitOfWork.Transferees.Add(transferee); } _unitOfWork.Orders.Add(order); IsNew = true; } else { _mapper.Map <OrderDto, Order>(orderDto, order); if (transferee == null) { transferee = _mapper.Map <TransfereeDto, Transferee>(orderDto.Transferee); transferee.InviteStatus = InviteStatus.NotYetInvited; _unitOfWork.Transferees.Add(transferee); } } //Add default services //Populate list of service categories available for this order. var cats = ServiceHelper.GetCategoriesForServiceFlag(order.ServiceFlag); //Get all service types that the order already has. var ids = order.Services.Select(s => s.ServiceTypeId).ToList(); IEnumerable <ServiceType> defServTypes = _unitOfWork.ServiceTypes.GetDefaultServiceTypes(cats, ids, order.IsInternational); foreach (var servType in defServTypes) { order.Services.Add(new Service() { Selected = true, ServiceType = servType }); } //Map type values if (!String.IsNullOrWhiteSpace(orderDto.BrokerFeeTypeSeValue)) { order.BrokerFeeType = _unitOfWork.BrokerFeeTypes.GetBrokerFeeType(orderDto.BrokerFeeTypeSeValue); } if (!String.IsNullOrWhiteSpace(orderDto.DepositTypeSeValue)) { order.DepositType = _unitOfWork.DepositTypes.GetDepositType(orderDto.DepositTypeSeValue); } order.TransfereeId = transferee.Id; order.ConsultantId = consultantId; order.ProgramManagerId = programManagerId; if (IsNew) { Notification notification = new Notification() { NotificationType = NotificationType.OrderCreated, Message = "Your manager has assigned you a new Transferee, their name is ", Title = "New Order Creation", OrderId = order.Id }; consultant.Notify(notification); } if (IsNew) { var homeFinding = new HomeFinding { Id = order.Id }; order.HomeFinding = homeFinding; } _unitOfWork.Complete(); }