示例#1
0
 public async Task <GenericActionResult <OrganisationProfile> > SaveOrganisationProfile(AddOrganisationProfileModel organisationProfileModel, string webRootPath, string userId)
 {
     try
     {
         if (context.OrganisationProfiles.FirstOrDefault(a => a.UserId.Equals(userId)) != null)
         {
             return(await UpdateOrganisationProfile(ObjectConverterManager.ToOrganisationProfileModel(organisationProfileModel, userId), webRootPath));
         }
         var profile = new OrganisationProfile
         {
             CompanyAddress            = organisationProfileModel.CompanyAddress,
             DateCreated               = DateTime.Now,
             UserId                    = userId,
             BusinessTypeId            = organisationProfileModel.CompanyBusinessType,
             CompanyName               = organisationProfileModel.CompanyName,
             CompanyPhoneNumber        = organisationProfileModel.CompanyPhoneNumber,
             CompanyRegistrationId     = organisationProfileModel.CompanyRegistrationId,
             CountryId                 = organisationProfileModel.CountryId,
             DateOfCompanyRegistration = organisationProfileModel.DateOfCompanyRegistration,
             ProfileImageName          = await UploadFile.SaveFileInWebRoot(organisationProfileModel.ProfileImage, webRootPath)
         };
         context.OrganisationProfiles.Add(profile);
         context.SaveChanges();
         return(new GenericActionResult <OrganisationProfile>(true, "Organisation profile saved successfully.", profile));
     }
     catch (Exception)
     {
         return(new GenericActionResult <OrganisationProfile>("Failed to save organisation profile, please try again or contact the administrator."));
     }
 }
示例#2
0
        public async Task <GenericActionResult <OrganisationProfile> > UpdateOrganisationProfile(OrganisationProfileModel organisationProfileModel, string webRootPath)
        {
            try
            {
                OrganisationProfile organisationProfile = context.OrganisationProfiles.Find(organisationProfileModel.Id);
                organisationProfile.CompanyAddress            = organisationProfileModel.CompanyAddress;
                organisationProfile.BusinessTypeId            = organisationProfileModel.CompanyBusinessType;
                organisationProfile.CompanyName               = organisationProfileModel.CompanyName;
                organisationProfile.CompanyPhoneNumber        = organisationProfileModel.CompanyPhoneNumber;
                organisationProfile.CompanyRegistrationId     = organisationProfileModel.CompanyRegistrationId;
                organisationProfile.CountryId                 = organisationProfileModel.CountryId;
                organisationProfile.DateOfCompanyRegistration = organisationProfileModel.DateOfCompanyRegistration;
                organisationProfile.ProfileImageName          = await UploadFile.SaveFileInWebRoot(organisationProfileModel.ProfileImage, webRootPath);

                context.SaveChanges();
                return(new GenericActionResult <OrganisationProfile>(true, "Organisation profile updated successfully.", organisationProfile));
            }
            catch (Exception)
            {
                return(new GenericActionResult <OrganisationProfile>("Failed to update organisation profile, please try again or contact the administrator."));
            }
        }
        public async Task <OrganisationProfileResponseModel> ToOrganisationProfileModel(OrganisationProfile organisationProfile, string webRootPath)
        {
            ApplicationUser user = await userManager.FindByIdAsync(organisationProfile.UserId);

            return(new OrganisationProfileResponseModel
            {
                UserId = user.Id,
                Id = organisationProfile.Id,
                ProfileImage = Convert.ToBase64String(File.ReadAllBytes(Path.Combine(webRootPath, organisationProfile.ProfileImageName))),
                Email = user.Email,
                UserName = user.UserName,
                Phonenumber = user.PhoneNumber,
                DateCreated = organisationProfile.DateCreated,
                CompanyAddress = organisationProfile.CompanyAddress,
                Country = context.Countries.Find(organisationProfile.CountryId),
                CompanyPhoneNumber = organisationProfile.CompanyPhoneNumber,
                CompanyName = organisationProfile.CompanyName,
                BusinessType = context.BusinessTypes.Find(organisationProfile.BusinessTypeId),
                DateOfCompanyRegistration = organisationProfile.DateOfCompanyRegistration,
                CompanyRegistrationId = organisationProfile.CompanyRegistrationId
            });
        }