Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }