Exemple #1
0
        public void SaveImage(ImageTypes type, string id, byte[] image)
        {
            switch (type)
            {
            case ImageTypes.Avatar:
                var up = _userProfileService.GetUserProfileForEditing(id);

                if (up != null)
                {
                    up.Image       = image;
                    up.LastUpdated = DateTime.UtcNow;

                    _userProfileService.SaveProfile(0, up);
                }
                break;

            case ImageTypes.Department:
                var di = _departmentProfileService.GetOrInitializeDepartmentProfile(int.Parse(id));

                if (di != null)
                {
                    di.Logo = image;
                    _departmentProfileService.SaveDepartmentProfile(di);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
Exemple #2
0
        public IActionResult Profile(ProfileView model)
        {
            model.ApiUrl     = _appOptionsAccessor.Value.ResgridApiUrl;
            model.Department = _departmentsService.GetDepartmentByUserId(UserId);
            model.ImageUrl   = $"{model.ApiUrl}/api/v3/Avatars/Get?id={model.Department.DepartmentId}&type=1";

            if (ModelState.IsValid)
            {
                var profile = _departmentProfileService.GetOrInitializeDepartmentProfile(DepartmentId);
                profile.DepartmentId = DepartmentId;

                profile.Disabled                    = model.Profile.Disabled;
                profile.Name                        = model.Profile.Name;
                profile.ShortName                   = model.Profile.ShortName;
                profile.Description                 = model.Profile.Description;
                profile.InCaseOfEmergency           = model.Profile.InCaseOfEmergency;
                profile.ServiceArea                 = model.Profile.ServiceArea;
                profile.ServicesProvided            = model.Profile.ServicesProvided;
                profile.Founded                     = model.Profile.Founded;
                profile.Keywords                    = model.Profile.Keywords;
                profile.InviteOnly                  = model.Profile.InviteOnly;
                profile.AllowMessages               = model.Profile.AllowMessages;
                profile.VolunteerPositionsAvailable = model.Profile.VolunteerPositionsAvailable;
                profile.ShareStats                  = model.Profile.ShareStats;
                profile.VolunteerKeywords           = model.Profile.VolunteerKeywords;
                profile.VolunteerDescription        = model.Profile.VolunteerDescription;
                profile.VolunteerContactName        = model.Profile.VolunteerContactName;
                profile.VolunteerContactInfo        = model.Profile.VolunteerContactInfo;
                profile.Latitude                    = model.Profile.Latitude;
                profile.Longitude                   = model.Profile.Longitude;
                profile.What3Words                  = model.Profile.What3Words;

                if (profile.AddressId.HasValue)
                {
                    var address = _addressService.GetAddressById(profile.AddressId.Value);
                    address.Address1   = model.Address1;
                    address.City       = model.City;
                    address.Country    = model.Country;
                    address.PostalCode = model.PostalCode;
                    address.State      = model.State;

                    _addressService.SaveAddress(address);
                }
                else if (!String.IsNullOrWhiteSpace(model.Address1) && !String.IsNullOrWhiteSpace(model.City) &&
                         !String.IsNullOrWhiteSpace(model.PostalCode) && !String.IsNullOrWhiteSpace(model.State) &&
                         !String.IsNullOrWhiteSpace(model.Country))
                {
                    var address = new Address();
                    address.Address1   = model.Address1;
                    address.City       = model.City;
                    address.Country    = model.Country;
                    address.PostalCode = model.PostalCode;
                    address.State      = model.State;

                    var savedAddress = _addressService.SaveAddress(address);
                    profile.AddressId = savedAddress.AddressId;
                }

                if (!String.IsNullOrWhiteSpace(profile.What3Words) &&
                    (String.IsNullOrWhiteSpace(profile.Latitude) && String.IsNullOrWhiteSpace(profile.Longitude)))
                {
                    var result = _geoLocationProvider.GetCoordinatesFromW3W(profile.What3Words);
                    if (result != null)
                    {
                        profile.Latitude  = result.Latitude.ToString();
                        profile.Longitude = result.Longitude.ToString();
                    }
                }

                if (String.IsNullOrWhiteSpace(profile.Latitude) && String.IsNullOrWhiteSpace(profile.Longitude))
                {
                    if (profile.AddressId.HasValue)
                    {
                        var address  = _addressService.GetAddressById(profile.AddressId.Value);
                        var location =
                            _geoLocationProvider.GetLatLonFromAddress(
                                $"{address.Address1} {address.City} {address.State} {address.PostalCode} {address.Country}");

                        if (!string.IsNullOrWhiteSpace(location))
                        {
                            var points = location.Split(char.Parse(","));
                            profile.Latitude  = points[0];
                            profile.Longitude = points[1];
                        }
                    }
                }

                _departmentProfileService.SaveDepartmentProfile(profile);

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }