コード例 #1
0
        public ActionResult Edit(AssociateManageModel model, string returnUrl, SubmitType submit)
        {
            if (ModelState.IsValid)
            {
                var response = _associateService.SaveAssociate(model);
                SetResponseMessage(response);
                if (response.Success)
                {
                    switch (submit)
                    {
                    case SubmitType.Save:
                        if (!string.IsNullOrEmpty(returnUrl))
                        {
                            return(Redirect(returnUrl));
                        }

                        return(RedirectToAction("Index"));

                    default:
                        return(RedirectToAction("Edit", new { id = model.Id, returnUrl }));
                    }
                }
            }
            return(View(model));
        }
コード例 #2
0
        /// <summary>
        /// Update Associate data
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel UpdateAssociateData(XEditableModel model)
        {
            var associate = GetById(model.Pk);

            if (associate != null)
            {
                var property =
                    ReflectionUtilities.GetAllPropertiesOfType(typeof(AssociateManageModel))
                    .FirstOrDefault(p => p.Name.Equals(model.Name, StringComparison.CurrentCultureIgnoreCase));
                if (property != null)
                {
                    // Generate property value
                    object value = model.Value.ToType(property, WorkContext.CurrentTimezone);

                    #region Validate

                    var manageModel = new AssociateManageModel(associate);
                    manageModel.SetProperty(model.Name, value);
                    var validationResults = manageModel.ValidateModel();

                    if (validationResults.Any())
                    {
                        return(new ResponseModel
                        {
                            Success = false,
                            Message = validationResults.BuildValidationMessages()
                        });
                    }

                    #endregion

                    associate.SetProperty(model.Name, value);

                    var response = Update(associate);
                    return(response.SetMessage(response.Success
                        ? T("Associate_Message_UpdateAssociateInfoSuccessfully")
                        : T("Associate_Message_UpdateAssociateInfoFailure")));
                }
                return(new ResponseModel
                {
                    Success = false,
                    Message = T("Associate_Message_PropertyNotFound")
                });
            }

            return(new ResponseModel
            {
                Success = false,
                Message = T("Associate_Message_ObjectNotFound")
            });
        }
コード例 #3
0
        public ActionResult Create(AssociateManageModel model, SubmitType submit)
        {
            if (ModelState.IsValid)
            {
                var response = _associateService.SaveAssociate(model);
                SetResponseMessage(response);
                if (response.Success)
                {
                    var id = (int)response.Data;
                    switch (submit)
                    {
                    case SubmitType.Save:
                        return(RedirectToAction("Index"));

                    default:
                        return(RedirectToAction("Edit", new { id }));
                    }
                }
            }
            return(View(model));
        }
コード例 #4
0
        public ActionResult PopupEdit(AssociateManageModel model, SubmitType submit)
        {
            if (ModelState.IsValid)
            {
                var response = _associateService.SaveAssociate(model);
                SetResponseMessage(response);
                if (response.Success)
                {
                    switch (submit)
                    {
                    case SubmitType.PopupSave:
                        return(View("CloseFancyBox", new CloseFancyBoxViewModel()));

                    case SubmitType.SaveAndContinueEdit:
                        return(RedirectToAction("PopupEdit", new { id = model.Id }));
                    }
                }
            }
            SetupPopupAction();
            return(View(model));
        }
コード例 #5
0
        /// <summary>
        /// Save Associate
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel SaveAssociate(AssociateManageModel model)
        {
            ResponseModel response;

            var associate = GetById(model.Id);

            if (associate != null)
            {
                associate.Title                 = model.Title;
                associate.JobTitle              = model.JobTitle;
                associate.FirstName             = model.FirstName;
                associate.LastName              = model.LastName;
                associate.Email                 = model.Email;
                associate.AddressLine1          = model.AddressLine1;
                associate.AddressLine2          = model.AddressLine2;
                associate.Suburb                = model.Suburb;
                associate.State                 = model.State;
                associate.Postcode              = model.Postcode;
                associate.Country               = model.Country;
                associate.PhoneWork             = model.PhoneWork;
                associate.PhoneHome             = model.PhoneHome;
                associate.MobilePhone           = model.MobilePhone;
                associate.Fax                   = model.Fax;
                associate.Gender                = model.Gender;
                associate.Photo                 = model.Photo;
                associate.University            = model.University;
                associate.Qualification         = model.Qualification;
                associate.OtherQualification    = model.OtherQualification;
                associate.Achievements          = model.Achievements;
                associate.Memberships           = model.Memberships;
                associate.Appointments          = model.Appointments;
                associate.PersonalInterests     = model.PersonalInterests;
                associate.ProfessionalInterests = model.ProfessionalInterests;
                associate.Positions             = model.Positions;
                associate.IsNew                 = model.IsNew;
                associate.DateStart             = model.DateStart;
                associate.DateEnd               = model.DateEnd;

                associate.Company = _companyService.SaveCompany(model.Company);

                #region Associate Types

                var currentAssociateTypes = associate.AssociateAssociateTypes.Select(nc => nc.AssociateTypeId).ToList();

                if (model.AssociateTypeIds == null)
                {
                    model.AssociateTypeIds = new List <int>();
                }

                // Remove reference to deleted types
                var removedAssociateTypeIds = currentAssociateTypes.Where(id => !model.AssociateTypeIds.Contains(id));
                _associateAssociateTypeRepository.DeleteByAssociateTypeId(associate.Id, removedAssociateTypeIds);

                // Add new reference to types
                var addedAssociateTypeIds = model.AssociateTypeIds.Where(id => !currentAssociateTypes.Contains(id));
                _associateAssociateTypeRepository.InsertByAssociateId(associate.Id, addedAssociateTypeIds);

                #endregion

                #region Company Types

                var currentCompanyTypes = associate.AssociateCompanyTypes.Select(nc => nc.CompanyTypeId).ToList();

                if (model.CompanyTypeIds == null)
                {
                    model.CompanyTypeIds = new List <int>();
                }

                // Remove reference to deleted types
                var removedCompanyTypeIds = currentCompanyTypes.Where(id => !model.CompanyTypeIds.Contains(id));
                _associateCompanyTypeRepository.DeleteByAssociateId(associate.Id, removedCompanyTypeIds);

                // Add new reference to types
                var addedCompanyTypeIds = model.CompanyTypeIds.Where(id => !currentCompanyTypes.Contains(id));
                _associateCompanyTypeRepository.InsertByAssociateId(associate.Id, addedCompanyTypeIds);

                #endregion

                #region Locations

                var currentLocations = associate.AssociateLocations.Select(nc => nc.LocationId).ToList();

                if (model.LocationIds == null)
                {
                    model.LocationIds = new List <int>();
                }

                // Remove reference to deleted locations
                var removedLocationIds = currentLocations.Where(id => !model.LocationIds.Contains(id));
                _associateLocationRepository.DeleteByAssociateId(associate.Id, removedLocationIds);

                // Add new reference to locations
                var addedLocationIds = model.LocationIds.Where(id => !currentLocations.Contains(id));
                _associateLocationRepository.InsertByAssociateId(associate.Id, addedLocationIds);

                #endregion

                response = Update(associate);
                return(response.SetMessage(response.Success
                    ? T("Associate_Message_UpdateSuccessfully")
                    : T("Associate_Message_UpdateFailure")));
            }
            Mapper.CreateMap <AssociateManageModel, Associate>();
            associate = Mapper.Map <AssociateManageModel, Associate>(model);

            associate.Company = _companyService.SaveCompany(model.Company);

            response = Insert(associate);

            #region Associate Types

            if (model.AssociateTypeIds == null)
            {
                model.AssociateTypeIds = new List <int>();
            }

            _associateAssociateTypeRepository.InsertByAssociateId(associate.Id, model.AssociateTypeIds);

            #endregion

            #region Company Types

            if (model.CompanyTypeIds == null)
            {
                model.CompanyTypeIds = new List <int>();
            }

            _associateCompanyTypeRepository.InsertByAssociateId(associate.Id, model.CompanyTypeIds);

            #endregion

            #region Locations

            if (model.LocationIds == null)
            {
                model.LocationIds = new List <int>();
            }

            _associateLocationRepository.InsertByAssociateId(associate.Id, model.LocationIds);

            #endregion

            return(response.SetMessage(response.Success
                ? T("Associate_Message_CreateSuccessfully")
                : T("Associate_Message_CreateFailure")));
        }