Example #1
0
 public async Task <GenericActionResult <UserProfile> > SaveUserDetails(AddUserProfileModel userProfileModel, string webRootPath, string userId)
 {
     try
     {
         if (context.UserProfiles.FirstOrDefault(a => a.UserId.Equals(userId)) != null)
         {
             return(await UpdateUserDetails(ObjectConverterManager.ToUserProfileModel(userProfileModel, userId), webRootPath));
         }
         var userProfile = new UserProfile
         {
             CountryId        = userProfileModel.CountryId,
             DateOfBirth      = userProfileModel.DateOfBirth,
             FirstName        = userProfileModel.FirstName,
             Gender           = (byte)userProfileModel.Gender,
             LastName         = userProfileModel.LastName,
             UserId           = userId,
             DateCreated      = DateTime.Now,
             IsDeleted        = false,
             ProfileImageName = await UploadFile.SaveFileInWebRoot(userProfileModel.ProfileImage, webRootPath)
         };
         context.UserProfiles.Add(userProfile);
         context.SaveChanges();
         return(new GenericActionResult <UserProfile>(true, "User details saved successfully.", userProfile));
     }
     catch (Exception)
     {
         return(new GenericActionResult <UserProfile>("Failed to save user details, please try again or contact the administrator."));
     }
 }
Example #2
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."));
     }
 }
 public GenericActionResult <BusinessTypeModel> GetBusinessType(int id)
 {
     try
     {
         return(new GenericActionResult <BusinessTypeModel>(true, "", ObjectConverterManager.ToBusinessTypeModel(context.BusinessTypes.SingleOrDefaultAsync(m => m.Id == id && !m.IsDeleted).Result)));
     }
     catch (Exception)
     {
         return(new GenericActionResult <BusinessTypeModel>("Failed to get business type, please try again or contact the administrator."));
     }
 }
        public async Task <GenericActionResult <BusinessTypeModel> > DeleteBusinessTypeModel(int id)
        {
            try
            {
                var businessType = await context.BusinessTypes.SingleOrDefaultAsync(m => m.Id == id);

                if (businessType == null)
                {
                    return(new GenericActionResult <BusinessTypeModel>());
                }
                businessType.IsDeleted = true;
                await context.SaveChangesAsync();

                return(new GenericActionResult <BusinessTypeModel>(true, "Business type deleted successfully", ObjectConverterManager.ToBusinessTypeModel(businessType)));
            }
            catch (Exception)
            {
                return(new GenericActionResult <BusinessTypeModel>("Failed to delete business type, please try again or contact the administrator."));
            }
        }
        public async Task <GenericActionResult <BusinessTypeModel> > AddBusinessTypeModel(BusinessType businessType)
        {
            try
            {
                context.BusinessTypes.Add(businessType);
                await context.SaveChangesAsync();

                return(new GenericActionResult <BusinessTypeModel>(true, "Business type saved successfully", ObjectConverterManager.ToBusinessTypeModel(businessType)));
            }
            catch (Exception)
            {
                return(new GenericActionResult <BusinessTypeModel>("Failed to save business type, please try again or contact the administrator."));
            }
        }
        public async Task <GenericActionResult <BusinessTypeModel> > UpdateBusinessType(BusinessType businessType)
        {
            context.Entry(businessType).State = EntityState.Modified;
            try
            {
                await context.SaveChangesAsync();

                return(new GenericActionResult <BusinessTypeModel>(true, "Business type updated successfully", ObjectConverterManager.ToBusinessTypeModel(businessType)));
            }
            catch (DbUpdateConcurrencyException)
            {
                return(new GenericActionResult <BusinessTypeModel>("Failed to update business type, please try again or contact the administrator."));
            }
        }