public ActionResult Edit(LocationManageModel model, string returnUrl, SubmitType submit)
        {
            if (ModelState.IsValid)
            {
                var response = _locationService.SaveLocation(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));
        }
Exemple #2
0
        /// <summary>
        /// Update Location data
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel UpdateLocationData(XEditableModel model)
        {
            var location = GetById(model.Pk);

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

                    #region Validate

                    var manageModel = new LocationManageModel(location);
                    manageModel.SetProperty(model.Name, value);

                    var validationResults = manageModel.ValidateModel();

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

                    #endregion

                    location.SetProperty(model.Name, value);

                    var response = Update(location);
                    return(response.SetMessage(response.Success
                        ? T("Location_Message_UpdateLocationInfoSuccessfully")
                        : T("Location_Message_UpdateLocationInfoFailure")));
                }
                return(new ResponseModel
                {
                    Success = false,
                    Message = T("Location_Message_PropertyNotFound")
                });
            }

            return(new ResponseModel
            {
                Success = false,
                Message = T("Location_Message_ObjectNotFound")
            });
        }
        public ActionResult Create(LocationManageModel model, SubmitType submit)
        {
            if (ModelState.IsValid)
            {
                var response = _locationService.SaveLocation(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));
        }
        public ActionResult PopupEdit(LocationManageModel model, SubmitType submit)
        {
            if (ModelState.IsValid)
            {
                var response = _locationService.SaveLocation(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));
        }
Exemple #5
0
        /// <summary>
        /// Save Location
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel SaveLocation(LocationManageModel model)
        {
            ResponseModel response;
            var           location = GetById(model.Id);

            if (location != null)
            {
                location.Name                 = model.Name;
                location.ContactName          = model.ContactName;
                location.ContactTitle         = model.ContactTitle;
                location.AddressLine1         = model.AddressLine1;
                location.AddressLine2         = model.AddressLine2;
                location.Suburb               = model.Suburb;
                location.State                = model.State;
                location.Postcode             = model.Postcode;
                location.Country              = model.Country;
                location.Latitude             = model.Latitude;
                location.Longitude            = model.Longitude;
                location.Phone                = model.Phone;
                location.Fax                  = model.Fax;
                location.Email                = model.Email;
                location.TrainingAffiliation  = model.TrainingAffiliation;
                location.PinImage             = model.PinImage;
                location.OpeningHoursWeekdays = model.OpeningHoursWeekdays;
                location.OpeningHoursSaturday = model.OpeningHoursSaturday;
                location.OpeningHoursSunday   = model.OpeningHoursSunday;
                location.TimeZone             = model.TimeZone;

                #region Location Types

                var currentTypes = location.LocationLocationTypes.Select(nc => nc.LocationTypeId).ToList();

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

                // Remove reference to deleted types
                var removedTypeIds = currentTypes.Where(id => !model.LocationTypeIds.Contains(id));
                _locationLocationTypeRepository.DeleteByLocationTypeId(location.Id, removedTypeIds);

                // Add new reference to types
                var addedTypeIds = model.LocationTypeIds.Where(id => !currentTypes.Contains(id));
                _locationLocationTypeRepository.Insert(location.Id, addedTypeIds);

                #endregion

                response = Update(location);
                return(response.SetMessage(response.Success
                    ? T("Location_Message_UpdateSuccessfully")
                    : T("Location_Message_UpdateFailure")));
            }
            Mapper.CreateMap <LocationManageModel, Location>();
            location = Mapper.Map <LocationManageModel, Location>(model);
            response = Insert(location);

            #region Location Types

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

            _locationLocationTypeRepository.Insert(location.Id, model.LocationTypeIds);

            #endregion

            return(response.SetMessage(response.Success
                ? T("Location_Message_CreateSuccessfully")
                : T("Location_Message_CreateFailure")));
        }