public ResultDto SendInvitation(InviteMemberBm bm) { var vService = this.vehicleService.GetVehiceService(bm.Id); if (vService == null) { return(new ResultDto("Cannot send membership invitation!")); } var isSame = vService.ServiceMembers .FirstOrDefault(x => x.IsVehicleServiceOwner).ApplicationUser.Email == bm.MemberEmail; if (isSame) { return(new ResultDto("Cannot send membership invitation!")); } var membershipInvitation = new MembershipInvitation() { VehicleServiceId = bm.Id, VehicleServiceName = vService.Name, MemberEmail = bm.MemberEmail }; bool isAdded = this.vehicleService.AddMembershipInvitation(membershipInvitation); if (!isAdded) { return(new ResultDto("Cannot send membership invitation!")); } return(null); }
public bool AddMembershipInvitation(MembershipInvitation membershipInvitation) { var isExist = this.context.AppUsers.Any(x => x.Email == membershipInvitation.MemberEmail); if (!isExist) { return(false); } // check for spam ... if there is active invitation, service cannot send another one. var isDuplicate = this.context.MembershipInvitations.Any(x => x.VehicleServiceId == membershipInvitation.VehicleServiceId && x.VehicleServiceName == membershipInvitation.VehicleServiceName && x.MemberEmail == membershipInvitation.MemberEmail && !x.IsDeleted); var alreadyMember = this.context.MembershipInvitations.Any(x => x.VehicleServiceId == membershipInvitation.VehicleServiceId && x.VehicleServiceName == membershipInvitation.VehicleServiceName && x.MemberEmail == membershipInvitation.MemberEmail && x.IsAccepted); if (isDuplicate || alreadyMember) { return(false); } try { this.context.MembershipInvitations.Add(membershipInvitation); this.context.Commit(); } catch (Exception ex) { return(this.LogError(ex)); } return(true); }