public ServiceResponse GetBusinessModel(UserSessionModel admin, long?businessId, bool isEditing = false) { BusinessModel model = null; if (businessId.HasValue) { var query = from business in this.Db.BusinessQueryByBusinessId(admin, businessId.Value) join bustype in this.Db.BusinessTypes on business.BusinessTypeId equals bustype.BusinessTypeId into Lbt from bustype in Lbt select new BusinessModel { BusinessId = business.BusinessId, BusinessName = business.BusinessName, AccountId = business.AccountId, DaikinCityId = business.DaikinCityId, ShowPricing = business.ShowPricing, CommissionSchemeAllowed = business.CommissionSchemeAllowed, BusinessTypeId = (int)business.BusinessTypeId, BusinessTypeDescription = bustype.Description, Enabled = business.Enabled, Timestamp = business.Timestamp, ERPAccountId = (business.ERPAccountId == null) ? null : business.ERPAccountId, Address = new AddressModel { AddressId = business.AddressId, }, Contact = new ContactModel { ContactId = business.ContactId, }, AccountManagerEmail = business.AccountManagerEmail, AccountOwnerEmail = business.AccountOwnerEmail, IsDaikinBranch = (business.BusinessTypeId == (BusinessTypeEnum)200002) ? true : false, IsDaikinComfortPro = business.IsDaikinComfortPro, IsVRVPro = business.IsVRVPro }; model = query.FirstOrDefault(); //Get Parent Business if available var businessLink = this.Db.BusinessLinkQueryByBusinessId(model.BusinessId).FirstOrDefault(); if (businessLink != null) { if (businessLink.BusinessId != businessLink.ParentBusinessId)// this check to prevent infinite loop { SearchBusiness businessSearch = new SearchBusiness { BusinessId = businessLink.ParentBusinessId, ReturnTotals = true }; var resp = GetBusinessModel(admin, businessSearch); if (resp != null && resp.IsOK && resp.Model != null) { var parentBusiness = resp.Model as BusinessModel; model.ParentBusinessId = (long)parentBusiness.BusinessId; model.ParentBusinessName = parentBusiness.BusinessName; } } } if (model == null) { this.Response.AddError(Resources.DataMessages.DM006); } } model = model ?? new BusinessModel(); model.Address = addressService.GetAddressModel(admin, model.Address); model.Contact = contactService.GetContactModel(admin, model.Contact); FinaliseModel(admin, model, isEditing); this.Response.Model = model; return(this.Response); }
public ServiceResponse GetUserModel(UserSessionModel user, UserModel templateModel, bool isEditing = false) { UserModel model = null; if (templateModel != null) { var userId = templateModel.UserId; if (userId.HasValue) { var query = from u in this.Db.QueryUserViewableByUserId(user, userId.Value) select new UserModel { UserId = u.UserId, Email = u.Email, FirstName = u.FirstName, MiddleName = u.MiddleName, LastName = u.LastName, Enabled = u.Enabled, Business = new BusinessModel { BusinessId = u.BusinessId }, // AddressId = user.AddressId, //ContactId = user.ContactId, ShowPricing = u.ShowPricing, UseBusinessAddress = u.UseBusinessAddress, UserTypeId = (UserTypeEnum?)u.UserTypeId, Approved = u.Approved, Timestamp = u.Timestamp, Address = new AddressModel { AddressId = u.AddressId, }, Contact = new ContactModel { ContactId = u.ContactId, } }; model = query.FirstOrDefault(); //Get Parent Business if available // Moved to GetBusinessModel() //var businessLink = this.Db.BusinessLinkQueryByBusinessId(model.Business.BusinessId).FirstOrDefault(); //if (businessLink != null) //{ // SearchBusiness businessSearch = new SearchBusiness // { // BusinessId = businessLink.ParentBusinessId, // ReturnTotals = true // }; // var resp = businessService.GetBusinessModel(user, businessSearch); // if (resp != null && resp.IsOK && resp.Model != null) // { // var parentBusiness = resp.Model as BusinessModel; // model.Business.ParentBusinessId = (long)parentBusiness.BusinessId; // model.Business.ParentBusinessName = parentBusiness.BusinessName; // } //} if (model == null) { this.Response.AddError(Resources.DataMessages.DM004); } } } model = model ?? new UserModel(); var userTypeChanged = false; // Setup from templateModel if (templateModel != null) { //if (model.UserTypeId != templateModel.UserTypeId) userTypeChanged = true; this line causing the problem, comment by aaron if (templateModel.UserTypeId.HasValue) { model.UserTypeId = templateModel.UserTypeId; } model.IsRegistering = templateModel.IsRegistering; } // Load Model Children addressService.BeginPropertyReference(this, "Address"); model.Address = addressService.GetAddressModel(user, model.Address); addressService.EndPropertyReference(); contactService.BeginPropertyReference(this, "Contact"); model.Contact = contactService.GetContactModel(user, model.Contact); contactService.EndPropertyReference(); businessService.BeginPropertyReference(this, "Business"); model.Business = businessService.GetBusinessModel(user, model.Business.BusinessId, true).Model as BusinessModel; businessService.EndPropertyReference(); FinaliseModel(user, model, isEditing, userTypeChanged); this.Response.Model = model; return(this.Response); }
public void FinaliseOrderModel(UserSessionModel admin, OrderViewModel model) { if (!string.IsNullOrEmpty(model.ProjectId.ToString()) && !string.IsNullOrEmpty(model.QuoteId.ToString())) { var projectQuery = from project in this.Db.QueryProjectViewableByProjectId(admin, model.ProjectId) join quote in this.Db.Quotes on new { id = project.ProjectId, qId = model.QuoteId } equals new { id = quote.ProjectId, qId = quote.QuoteId } into Laq from quote in Laq.DefaultIfEmpty() select new ProjectModel { ProjectId = project.ProjectId, OwnerId = project.Owner.UserId, Name = project.Name, Description = project.Description, ProjectDate = project.ProjectDate, BidDate = project.BidDate, EstimatedClose = project.EstimatedClose, EstimatedDelivery = project.EstimatedDelivery, Expiration = project.Expiration, ProjectStatusTypeId = (byte)project.ProjectStatusTypeId, ProjectTypeId = project.ProjectTypeId, ProjectOpenStatusTypeId = project.ProjectOpenStatusTypeId, ConstructionTypeId = project.ConstructionTypeId, VerticalMarketTypeId = project.VerticalMarketTypeId, CustomerAddress = new AddressModel { AddressId = project.CustomerAddressId, }, SellerAddress = new AddressModel { AddressId = project.SellerAddressId, }, EngineerAddress = new AddressModel { AddressId = project.EngineerAddressId, }, ShipToAddress = new AddressModel { AddressId = project.ShipToAddressId, }, ActiveQuoteSummary = new QuoteListModel { ProjectId = project.ProjectId, QuoteId = (quote == null) ? 0 : quote.QuoteId, //ItemCount = (quote == null) ? 0 : quote.QuoteItems.Count(), Alert = (quote == null) ? false : quote.RecalculationRequired, Title = (quote == null) ? "" : quote.Title, Timestamp = (quote == null) ? (DateTime?)null : quote.Timestamp, TotalList = (quote == null) ? 0 : quote.TotalList, TotalListSplit = (quote == null) ? 0 : quote.TotalListSplit, TotalListVRV = (quote == null) ? 0 : quote.TotalListVRV, TotalMisc = (quote == null) ? 0 : quote.TotalMisc, TotalNet = (quote == null) ? 0 : quote.TotalNet, TotalSell = (quote == null) ? 0 : quote.TotalSell, TotalSellSplit = (quote == null) ? 0 : quote.TotalSellSplit, TotalSellVRV = (quote == null) ? 0 : quote.TotalSellVRV, TotalCountSplit = (quote == null) ? 0 : quote.TotalCountSplit, TotalCountVRV = (quote == null) ? 0 : quote.TotalCountVRV, TotalCountVRVIndoor = (quote == null) ? 0 : quote.TotalCountVRVIndoor, TotalCountVRVOutdoor = (quote == null) ? 0 : quote.TotalCountVRVOutdoor, ApprovedCommissionPercentage = (quote == null) ? 0 : quote.ApprovedCommissionPercentage, ApprovedDiscountPercentage = (quote == null) ? 0 : quote.ApprovedDiscountPercentage, ApprovedDiscountPercentageSplit = (quote == null) ? 0 : quote.ApprovedDiscountPercentageSplit, ApprovedDiscountPercentageVRV = (quote == null) ? 0 : quote.ApprovedDiscountPercentageVRV, TotalNetCommission = (quote == null) ? 0 : quote.TotalNetCommission, TotalNetNonCommission = (quote == null) ? 0 : quote.TotalNetNonCommission, TotalNetSplit = (quote == null) ? 0 : quote.TotalNetSplit, TotalNetVRV = (quote == null) ? 0 : quote.TotalNetVRV, IsGrossMargin = (quote == null) ? false : quote.IsGrossMargin, TotalFreight = (quote == null) ? 0 : quote.TotalFreight, DiscountPercentage = (quote == null) ? 0 : quote.DiscountPercentage, CommissionPercentage = (quote == null) ? 0 : quote.CommissionPercentage, Revision = (quote == null) ? 0 : quote.Revision }, ConstructionTypeDescription = project.ConstructionType.Description, ProjectTypeDescription = project.ProjectType.Description, ProjectOpenStatusDescription = project.ProjectOpenStatusType.Description, ProjectStatusDescription = project.ProjectStatusType.Description, VerticalMarketDescription = project.VerticalMarketType.Description, Deleted = project.Deleted, Timestamp = project.Timestamp }; model.Project = projectQuery.FirstOrDefault(); var addressService = new AddressServices(this.Context); model.Project.SellerAddress = addressService.GetAddressModel(admin, model.Project.SellerAddress); model.Project.CustomerAddress = addressService.GetAddressModel(admin, model.Project.CustomerAddress); model.Project.EngineerAddress = addressService.GetAddressModel(admin, model.Project.EngineerAddress); model.Project.ShipToAddress = addressService.GetAddressModel(admin, model.Project.ShipToAddress); //model.QuoteItems = new QuoteServices(this.Context).GetQuoteItemListModel(admin, (long)model.QuoteId).Model as List<QuoteItemListModel>; model.QuoteItems = new QuoteServices(this.Context).GetQuoteItems(admin, (long)model.QuoteId).Model as List <QuoteItemModel>; } if (model == null) { this.Response.AddError(Resources.DataMessages.DM007); return; } #region commented //var service = new QuoteServices(); //if (model.ApprovedDiscount > 0) //{ // model.ApprovedTotals = service.CalculateTotalDiscountsApproved(model.Quote, model.ApprovedDiscount, // model.ApprovedDiscountSplit, model.ApprovedDiscountVRV, model.RequestedCommission); //} //else //{ // model.ApprovedTotals = service.CalculateTotalDiscountsApproved(model.Quote, model.RequestedDiscount, // model.RequestedDiscountSplit, model.RequestedDiscountVRV, model.RequestedCommission); //} //model.StandardTotals = service.CalculateTotalStandard(model.Quote); //model.RequestedDiscount *= 100M; //model.RequestedDiscountSplit *= 100M; //model.RequestedDiscountVRV *= 100M; //model.ApprovedDiscount *= 100M; //model.ApprovedDiscountSplit *= 100M; //model.ApprovedDiscountVRV *= 100M; //model.RequestedCommission *= 100; // Dropdowns //model.DiscountRequestStatusTypes = htmlService.DropDownModelDiscountRequestStatusTypes((model == null) ? null : model.DiscountRequestStatusTypeId); //model.SystemBasisDesignTypes = htmlService.DropDownModelSystemBasisDesignTypes((model == null) ? null : model.SystemBasisDesignTypeId); //model.ZoneStrategyTypes = htmlService.DropDownModelZoneStrategyTypes((model == null) ? null : model.ZoneStrategyTypeId); //model.BrandSpecifiedTypes = htmlService.DropDownModelBrandCompetitorTypes((model == null) ? null : model.BrandSpecifiedTypeId); //model.BrandApprovedTypes = htmlService.DropDownModelBrandCompetitorTypes((model == null) ? null : model.BrandApprovedTypeId); //model.DaikinEquipmentAtAdvantageTypes = htmlService.DropDownModelDaikinEquipmentAtAdvantageTypes((model == null) ? null : model.DaikinEquipmentAtAdvantageTypeId); //model.ProbabilityOfCloseTypes = htmlService.DropDownModelProbabilityOfCloseTypes((model == null) ? null : model.ProbabilityOfCloseTypeId); #endregion commented }