public IHttpActionResult AddNewPrimaryContact([FromBody] PrimaryContact newContact)
        {
            if (Equals(newContact, null))
            {
                return(BadRequest());
            }

            var contactAlreadyExists = _unitOfWork.PrimaryContacts.Find(pc => pc.Email == newContact.Email);

            if (!contactAlreadyExists.Any())
            {
                try
                {
                    _unitOfWork.PrimaryContacts.Add(newContact);
                    _unitOfWork.Complete();

                    var createdContact = _unitOfWork.PrimaryContacts.FindSingle(pc => pc.Email == newContact.Email);

                    return(Ok(DtoHelper.CreatePrimaryContactDto(createdContact)));
                }
                catch (Exception ex)
                {
                    _logger.FailedUpdateServerLog <Exception, object, object>(HttpContext.Current.User, ex.Message,
                                                                              ex.InnerException, DtoHelper.CreatePrimaryContactDto(newContact));

                    return(InternalServerError(ex));
                }
            }
            else
            {
                return(Conflict());
            }
        }
示例#2
0
        public HttpStatusCode AddNewPrimaryContact(PrimaryContact newContact)
        {
            bool contactAlreadyExists = _db.PrimaryContacts.Any(c => c.Email == newContact.Email);

            if (!contactAlreadyExists)
            {
                try
                {
                    _db.PrimaryContacts.Add(newContact);
                    _db.SaveChanges();

                    return(HttpStatusCode.OK);
                }
                catch (Exception ex)
                {
                    _mongoMongoLogger.FailedUpdateServerLog <Exception, object, object>(HttpContext.Current.User, ex.Message,
                                                                                        ex.InnerException, newContact);

                    return(HttpStatusCode.InternalServerError);
                }
            }
            else
            {
                return(HttpStatusCode.Conflict);
            }
        }
示例#3
0
        public HttpStatusCode UpdatePrimaryContact(PrimaryContact contact)
        {
            try
            {
                var contactToUpdate     = _db.PrimaryContacts.SingleOrDefault(c => c.Id == contact.Id);
                var contactBeforeUpdate = DtoHelper.CreatePrimaryContactDto(contactToUpdate);

                if (contactToUpdate != null)
                {
                    contactToUpdate.Name       = contact.Name;
                    contactToUpdate.Email      = contact.Email;
                    contactToUpdate.Telephone  = contact.Telephone;
                    contactToUpdate.Function   = contact.Function;
                    contactToUpdate.Salutation = contact.Salutation;
                    contactToUpdate.Fax        = contact.Fax;
                    contactToUpdate.Active     = contact.Active;
                }

                _db.SaveChanges();

                _mongoMongoLogger.SuccessfulUpdateServerLog(HttpContext.Current.User, contactBeforeUpdate, DtoHelper.CreatePrimaryContactDto(contactToUpdate));

                return(HttpStatusCode.OK);
            }
            catch (Exception ex)
            {
                _mongoMongoLogger.FailedUpdateServerLog <Exception, object, object>(HttpContext.Current.User, ex.Message,
                                                                                    ex.InnerException, contact);

                return(HttpStatusCode.InternalServerError);
            }
        }
        /// <summary>
        /// Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            // credit: http://stackoverflow.com/a/263416/677735
            unchecked // Overflow is fine, just wrap
            {
                int hash = 41;

                // Suitable nullity checks
                hash = hash * 59 + Id.GetHashCode();

                if (LocalArea != null)
                {
                    hash = hash * 59 + LocalArea.GetHashCode();
                }

                if (EquipmentCount != null)
                {
                    hash = hash * 59 + EquipmentCount.GetHashCode();
                }

                if (EquipmentTypeName != null)
                {
                    hash = hash * 59 + EquipmentTypeName.GetHashCode();
                }

                if (ProjectName != null)
                {
                    hash = hash * 59 + ProjectName.GetHashCode();
                }

                if (PrimaryContact != null)
                {
                    hash = hash * 59 + PrimaryContact.GetHashCode();
                }

                if (Status != null)
                {
                    hash = hash * 59 + Status.GetHashCode();
                }

                if (ProjectId != null)
                {
                    hash = hash * 59 + ProjectId.GetHashCode();
                }

                if (ExpectedStartDate != null)
                {
                    hash = hash * 59 + ExpectedStartDate.GetHashCode();
                }

                if (ExpectedEndDate != null)
                {
                    hash = hash * 59 + ExpectedEndDate.GetHashCode();
                }

                return(hash);
            }
        }
示例#5
0
        /// <summary>
        /// Returns true if ProjectSearchResultViewModel instances are equal
        /// </summary>
        /// <param name="other">Instance of ProjectSearchResultViewModel to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(ProjectSearchResultViewModel other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Id == other.Id ||
                     Id.Equals(other.Id)
                     ) &&
                 (
                     District == other.District ||
                     District != null &&
                     District.Equals(other.District)
                 ) &&
                 (
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                 ) &&
                 (
                     PrimaryContact == other.PrimaryContact ||
                     PrimaryContact != null &&
                     PrimaryContact.Equals(other.PrimaryContact)
                 ) &&
                 (
                     Hires == other.Hires ||
                     Hires != null &&
                     Hires.Equals(other.Hires)
                 ) &&
                 (
                     Requests == other.Requests ||
                     Requests != null &&
                     Requests.Equals(other.Requests)
                 ) &&
                 (
                     Status == other.Status ||
                     Status != null &&
                     Status.Equals(other.Status)
                 ) &&
                 (
                     RentalRequests == other.RentalRequests ||
                     RentalRequests != null &&
                     RentalRequests.SequenceEqual(other.RentalRequests)
                 ) &&
                 (
                     RentalAgreements == other.RentalAgreements ||
                     RentalAgreements != null &&
                     RentalAgreements.SequenceEqual(other.RentalAgreements)
                 ));
        }
        public Models.Person Build()
        {
            var person = new Models.Person(FirstNameState.Get(), LastNameState.Get());

            foreach (var contact in Contacts)
            {
                person.Add(contact);
            }
            person.SetPrimaryContact(PrimaryContact.Get());
            return(person);
        }
示例#7
0
        /// <summary>
        /// Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            // credit: http://stackoverflow.com/a/263416/677735
            unchecked // Overflow is fine, just wrap
            {
                int hash = 41;

                // Suitable nullity checks
                hash = hash * 59 + Id.GetHashCode();

                if (District != null)
                {
                    hash = hash * 59 + District.GetHashCode();
                }

                if (Name != null)
                {
                    hash = hash * 59 + Name.GetHashCode();
                }

                if (PrimaryContact != null)
                {
                    hash = hash * 59 + PrimaryContact.GetHashCode();
                }

                if (Hires != null)
                {
                    hash = hash * 59 + Hires.GetHashCode();
                }

                if (Requests != null)
                {
                    hash = hash * 59 + Requests.GetHashCode();
                }

                if (Status != null)
                {
                    hash = hash * 59 + Status.GetHashCode();
                }

                if (RentalRequests != null)
                {
                    hash = hash * 59 + RentalRequests.GetHashCode();
                }

                if (RentalAgreements != null)
                {
                    hash = hash * 59 + RentalAgreements.GetHashCode();
                }

                return(hash);
            }
        }
        public static PrimaryContactDto CreatePrimaryContactDto(PrimaryContact contact)
        {
            var contactDto = new PrimaryContactDto()
            {
                Id         = contact.Id,
                Name       = contact.Name,
                Email      = contact.Email,
                Function   = contact.Function,
                Salutation = contact.Salutation,
                Telephone  = contact.Telephone,
                Fax        = contact.Fax,
                Active     = contact.Active,
                Version    = contact.Version
            };

            return(contactDto);
        }
示例#9
0
        public override int GetHashCode()
        {
            int hashCode = 0;

            if (Name != null)
            {
                hashCode ^= Name.GetHashCode();
            }
            if (PrimaryContact != null)
            {
                hashCode ^= PrimaryContact.GetHashCode();
            }
            if (AccountsPayableContact != null)
            {
                hashCode ^= AccountsPayableContact.GetHashCode();
            }

            return(hashCode);
        }
        public IHttpActionResult UpdatePrimaryContact(PrimaryContact contact)
        {
            if (Equals(contact, null))
            {
                return(BadRequest());
            }

            var contactToUpdate = _unitOfWork.PrimaryContacts.FindSingle(pc => pc.Id == contact.Id);

            if (Equals(contactToUpdate, null))
            {
                return(BadRequest());
            }

            var contactBeforeUpdate = DtoHelper.CreatePrimaryContactDto(contactToUpdate);

            try
            {
                contactToUpdate.Name       = contact.Name;
                contactToUpdate.Email      = contact.Email;
                contactToUpdate.Telephone  = contact.Telephone;
                contactToUpdate.Function   = contact.Function;
                contactToUpdate.Salutation = contact.Salutation;
                contactToUpdate.Fax        = contact.Fax;
                contactToUpdate.Active     = contact.Active;
                contactToUpdate.Version    = contactToUpdate.Version + 1;

                _unitOfWork.Complete();

                _logger.SuccessfulUpdateServerLog(HttpContext.Current.User, contactBeforeUpdate, DtoHelper.CreatePrimaryContactDto(_unitOfWork.PrimaryContacts.FindSingle(pc => pc.Id == contact.Id)));

                return(Ok(DtoHelper.CreatePrimaryContactDto(contactToUpdate)));
            }
            catch (Exception ex)
            {
                _logger.FailedUpdateServerLog <Exception, object, object>(HttpContext.Current.User, ex.Message,
                                                                          ex.InnerException, contact);

                return(InternalServerError());
            }
        }
示例#11
0
        public async Task <ActionResult> Delete(Guid id)
        {
            Registration registration = await _context.Registrations
                                        .Where(r => r.Id == id)
                                        .Include(r => r.Registrant)
                                        .Include(r => r.PrimaryContact)
                                        .FirstOrDefaultAsync();

            if (registration == null)
            {
                return(NotFound());
            }

            Registrant registrant = await _context.Registrants
                                    .Where(r => r.Id == registration.Registrant.Id)
                                    .Include(r => r.Registrations)
                                    .FirstOrDefaultAsync();

            PrimaryContact primaryContact = await _context.PrimaryContacts
                                            .Where(p => p.Id == registration.PrimaryContact.Id)
                                            .Include(p => p.Registrations)
                                            .FirstOrDefaultAsync();

            _context.Registrations.Remove(registration);

            // If no other registrations for registrant, remove as well
            if (registrant.Registrations.Count == 1)
            {
                _context.Registrants.Remove(registrant);
            }

            // If no other registrations for primary contact, remove as well
            if (primaryContact.Registrations.Count == 1)
            {
                _context.PrimaryContacts.Remove(primaryContact);
            }

            await _context.SaveChangesAsync();

            return(Ok());
        }
示例#12
0
        /// <inheritdoc/>
        public string ToDelimitedString()
        {
            CultureInfo culture = CultureInfo.CurrentCulture;

            return(string.Format(
                       culture,
                       StringHelper.StringFormatSequence(0, 12, Configuration.FieldSeparator),
                       Id,
                       SetIdVnd.HasValue ? SetIdVnd.Value.ToString(culture) : null,
                       VendorIdentifier?.ToDelimitedString(),
                       VendorName,
                       VendorCatalogNumber?.ToDelimitedString(),
                       PrimaryVendorIndicator?.ToDelimitedString(),
                       Corporation != null ? string.Join(Configuration.FieldRepeatSeparator, Corporation.Select(x => x.ToDelimitedString())) : null,
                       PrimaryContact?.ToDelimitedString(),
                       ContractAdjustment?.ToDelimitedString(),
                       AssociatedContractId != null ? string.Join(Configuration.FieldRepeatSeparator, AssociatedContractId.Select(x => x.ToDelimitedString())) : null,
                       ClassOfTrade != null ? string.Join(Configuration.FieldRepeatSeparator, ClassOfTrade) : null,
                       PricingTierLevel?.ToDelimitedString()
                       ).TrimEnd(Configuration.FieldSeparator.ToCharArray()));
        }
示例#13
0
        public IHttpActionResult AssignPrimaryContactToGln(int glnId, [FromBody] PrimaryContact selectedContact)
        {
            var glnToUpdate     = _unitOfWork.Glns.FindSingle(b => b.Id == glnId);
            var glnBeforeUpdate = DtoHelper.CreateGlnDto(glnToUpdate);

            try
            {
                var currentDbVersion = _unitOfWork.Glns.FindSingle(g => g.Id == glnId).Version;

                if (ConcurrencyChecker.canSaveChanges(glnToUpdate.Version, currentDbVersion) && _unitOfWork.Glns.PrimaryContactExists(selectedContact.Id))
                {
                    glnToUpdate.ContactId = selectedContact.Id;
                    glnToUpdate.Version   = glnToUpdate.Version + 1;
                    _unitOfWork.Complete();

                    var assignedDetails =
                        $"Contact {selectedContact.Name}, Id: {selectedContact.Id} " +
                        $"was assigned to GLN: {glnToUpdate.OwnGln}";

                    _logger.SuccessfulUpdateServerLog(HttpContext.Current.User, glnBeforeUpdate, assignedDetails);

                    return(Ok(DtoHelper.CreateGlnIncludeChildrenDto(glnToUpdate)));
                }
                else
                {
                    return(Conflict());
                }
            }
            catch (Exception ex)
            {
                var failedMsg =
                    $"Failed to assign contact {selectedContact.Name}, Id: {selectedContact.Id} to GLN: {glnToUpdate.OwnGln}. Exception generated: {ex}";

                _logger.FailedUpdateServerLog <Exception, string, object>(HttpContext.Current.User, ex.Message, ex.InnerException, failedMsg);

                return(InternalServerError());
            }
        }
示例#14
0
        /// <summary>
        /// Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            // credit: http://stackoverflow.com/a/263416/677735
            unchecked // Overflow is fine, just wrap
            {
                int hash = 41;

                // Suitable nullity checks
                hash = hash * 59 + Id.GetHashCode();

                if (OwnerEquipmentCodePrefix != null)
                {
                    hash = hash * 59 + OwnerEquipmentCodePrefix.GetHashCode();
                }

                if (OrganizationName != null)
                {
                    hash = hash * 59 + OrganizationName.GetHashCode();
                }

                hash = hash * 59 + MeetsResidency.GetHashCode();

                if (LocalArea != null)
                {
                    hash = hash * 59 + LocalArea.GetHashCode();
                }

                if (Status != null)
                {
                    hash = hash * 59 + Status.GetHashCode();
                }

                if (DoingBusinessAs != null)
                {
                    hash = hash * 59 + DoingBusinessAs.GetHashCode();
                }

                if (RegisteredCompanyNumber != null)
                {
                    hash = hash * 59 + RegisteredCompanyNumber.GetHashCode();
                }

                if (PrimaryContact != null)
                {
                    hash = hash * 59 + PrimaryContact.GetHashCode();
                }

                if (IsMaintenanceContractor != null)
                {
                    hash = hash * 59 + IsMaintenanceContractor.GetHashCode();
                }

                if (WorkSafeBCPolicyNumber != null)
                {
                    hash = hash * 59 + WorkSafeBCPolicyNumber.GetHashCode();
                }

                if (WorkSafeBCExpiryDate != null)
                {
                    hash = hash * 59 + WorkSafeBCExpiryDate.GetHashCode();
                }

                if (CGLEndDate != null)
                {
                    hash = hash * 59 + CGLEndDate.GetHashCode();
                }

                if (ArchiveCode != null)
                {
                    hash = hash * 59 + ArchiveCode.GetHashCode();
                }

                if (ArchiveReason != null)
                {
                    hash = hash * 59 + ArchiveReason.GetHashCode();
                }

                if (ArchiveDate != null)
                {
                    hash = hash * 59 + ArchiveDate.GetHashCode();
                }

                if (Contacts != null)
                {
                    hash = hash * 59 + Contacts.GetHashCode();
                }

                if (Notes != null)
                {
                    hash = hash * 59 + Notes.GetHashCode();
                }

                if (Attachments != null)
                {
                    hash = hash * 59 + Attachments.GetHashCode();
                }

                if (History != null)
                {
                    hash = hash * 59 + History.GetHashCode();
                }

                if (EquipmentList != null)
                {
                    hash = hash * 59 + EquipmentList.GetHashCode();
                }

                return(hash);
            }
        }
示例#15
0
        /// <summary>
        /// Returns true if Owner instances are equal
        /// </summary>
        /// <param name="other">Instance of Owner to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Owner other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Id == other.Id ||
                     Id.Equals(other.Id)
                     ) &&
                 (
                     OwnerEquipmentCodePrefix == other.OwnerEquipmentCodePrefix ||
                     OwnerEquipmentCodePrefix != null &&
                     OwnerEquipmentCodePrefix.Equals(other.OwnerEquipmentCodePrefix)
                 ) &&
                 (
                     OrganizationName == other.OrganizationName ||
                     OrganizationName != null &&
                     OrganizationName.Equals(other.OrganizationName)
                 ) &&
                 (
                     MeetsResidency == other.MeetsResidency ||
                     MeetsResidency.Equals(other.MeetsResidency)
                 ) &&
                 (
                     LocalArea == other.LocalArea ||
                     LocalArea != null &&
                     LocalArea.Equals(other.LocalArea)
                 ) &&
                 (
                     Status == other.Status ||
                     Status != null &&
                     Status.Equals(other.Status)
                 ) &&
                 (
                     DoingBusinessAs == other.DoingBusinessAs ||
                     DoingBusinessAs != null &&
                     DoingBusinessAs.Equals(other.DoingBusinessAs)
                 ) &&
                 (
                     RegisteredCompanyNumber == other.RegisteredCompanyNumber ||
                     RegisteredCompanyNumber != null &&
                     RegisteredCompanyNumber.Equals(other.RegisteredCompanyNumber)
                 ) &&
                 (
                     PrimaryContact == other.PrimaryContact ||
                     PrimaryContact != null &&
                     PrimaryContact.Equals(other.PrimaryContact)
                 ) &&
                 (
                     IsMaintenanceContractor == other.IsMaintenanceContractor ||
                     IsMaintenanceContractor != null &&
                     IsMaintenanceContractor.Equals(other.IsMaintenanceContractor)
                 ) &&
                 (
                     WorkSafeBCPolicyNumber == other.WorkSafeBCPolicyNumber ||
                     WorkSafeBCPolicyNumber != null &&
                     WorkSafeBCPolicyNumber.Equals(other.WorkSafeBCPolicyNumber)
                 ) &&
                 (
                     WorkSafeBCExpiryDate == other.WorkSafeBCExpiryDate ||
                     WorkSafeBCExpiryDate != null &&
                     WorkSafeBCExpiryDate.Equals(other.WorkSafeBCExpiryDate)
                 ) &&
                 (
                     CGLEndDate == other.CGLEndDate ||
                     CGLEndDate != null &&
                     CGLEndDate.Equals(other.CGLEndDate)
                 ) &&
                 (
                     ArchiveCode == other.ArchiveCode ||
                     ArchiveCode != null &&
                     ArchiveCode.Equals(other.ArchiveCode)
                 ) &&
                 (
                     ArchiveReason == other.ArchiveReason ||
                     ArchiveReason != null &&
                     ArchiveReason.Equals(other.ArchiveReason)
                 ) &&
                 (
                     ArchiveDate == other.ArchiveDate ||
                     ArchiveDate != null &&
                     ArchiveDate.Equals(other.ArchiveDate)
                 ) &&
                 (
                     Contacts == other.Contacts ||
                     Contacts != null &&
                     Contacts.SequenceEqual(other.Contacts)
                 ) &&
                 (
                     Notes == other.Notes ||
                     Notes != null &&
                     Notes.SequenceEqual(other.Notes)
                 ) &&
                 (
                     Attachments == other.Attachments ||
                     Attachments != null &&
                     Attachments.SequenceEqual(other.Attachments)
                 ) &&
                 (
                     History == other.History ||
                     History != null &&
                     History.SequenceEqual(other.History)
                 ) &&
                 (
                     EquipmentList == other.EquipmentList ||
                     EquipmentList != null &&
                     EquipmentList.SequenceEqual(other.EquipmentList)
                 ));
        }
示例#16
0
        /// <summary>
        /// Returns true if Project instances are equal
        /// </summary>
        /// <param name="other">Instance of Project to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Project other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Id == other.Id ||
                     Id.Equals(other.Id)
                     ) &&
                 (
                     District == other.District ||
                     District != null &&
                     District.Equals(other.District)
                 ) &&
                 (
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                 ) &&
                 (
                     Status == other.Status ||
                     Status != null &&
                     Status.Equals(other.Status)
                 ) &&
                 (
                     ProvincialProjectNumber == other.ProvincialProjectNumber ||
                     ProvincialProjectNumber != null &&
                     ProvincialProjectNumber.Equals(other.ProvincialProjectNumber)
                 ) &&
                 (
                     Information == other.Information ||
                     Information != null &&
                     Information.Equals(other.Information)
                 ) &&
                 (
                     RentalRequests == other.RentalRequests ||
                     RentalRequests != null &&
                     RentalRequests.SequenceEqual(other.RentalRequests)
                 ) &&
                 (
                     RentalAgreements == other.RentalAgreements ||
                     RentalAgreements != null &&
                     RentalAgreements.SequenceEqual(other.RentalAgreements)
                 ) &&
                 (
                     PrimaryContact == other.PrimaryContact ||
                     PrimaryContact != null &&
                     PrimaryContact.Equals(other.PrimaryContact)
                 ) &&
                 (
                     Contacts == other.Contacts ||
                     Contacts != null &&
                     Contacts.SequenceEqual(other.Contacts)
                 ) &&
                 (
                     Notes == other.Notes ||
                     Notes != null &&
                     Notes.SequenceEqual(other.Notes)
                 ) &&
                 (
                     Attachments == other.Attachments ||
                     Attachments != null &&
                     Attachments.SequenceEqual(other.Attachments)
                 ) &&
                 (
                     History == other.History ||
                     History != null &&
                     History.SequenceEqual(other.History)
                 ));
        }
示例#17
0
        /// <summary>
        /// Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            // credit: http://stackoverflow.com/a/263416/677735
            unchecked // Overflow is fine, just wrap
            {
                int hash = 41;

                // Suitable nullity checks
                hash = hash * 59 + Id.GetHashCode();

                if (District != null)
                {
                    hash = hash * 59 + District.GetHashCode();
                }

                if (Name != null)
                {
                    hash = hash * 59 + Name.GetHashCode();
                }

                if (Status != null)
                {
                    hash = hash * 59 + Status.GetHashCode();
                }

                if (ProvincialProjectNumber != null)
                {
                    hash = hash * 59 + ProvincialProjectNumber.GetHashCode();
                }

                if (Information != null)
                {
                    hash = hash * 59 + Information.GetHashCode();
                }

                if (RentalRequests != null)
                {
                    hash = hash * 59 + RentalRequests.GetHashCode();
                }

                if (RentalAgreements != null)
                {
                    hash = hash * 59 + RentalAgreements.GetHashCode();
                }

                if (PrimaryContact != null)
                {
                    hash = hash * 59 + PrimaryContact.GetHashCode();
                }

                if (Contacts != null)
                {
                    hash = hash * 59 + Contacts.GetHashCode();
                }

                if (Notes != null)
                {
                    hash = hash * 59 + Notes.GetHashCode();
                }

                if (Attachments != null)
                {
                    hash = hash * 59 + Attachments.GetHashCode();
                }

                if (History != null)
                {
                    hash = hash * 59 + History.GetHashCode();
                }

                return(hash);
            }
        }
 public IContanctHolder WithPrimaryContact(IContactInfo contact)
 {
     WithSecondaryContact(contact);
     PrimaryContact = PrimaryContact.Set(contact);
     return(this);
 }
        /// <summary>
        /// Returns true if RentalRequestSearchResultViewModel instances are equal
        /// </summary>
        /// <param name="other">Instance of RentalRequestSearchResultViewModel to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(RentalRequestSearchResultViewModel other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Id == other.Id ||
                     Id.Equals(other.Id)
                     ) &&
                 (
                     LocalArea == other.LocalArea ||
                     LocalArea != null &&
                     LocalArea.Equals(other.LocalArea)
                 ) &&
                 (
                     EquipmentCount == other.EquipmentCount ||
                     EquipmentCount != null &&
                     EquipmentCount.Equals(other.EquipmentCount)
                 ) &&
                 (
                     EquipmentTypeName == other.EquipmentTypeName ||
                     EquipmentTypeName != null &&
                     EquipmentTypeName.Equals(other.EquipmentTypeName)
                 ) &&
                 (
                     ProjectName == other.ProjectName ||
                     ProjectName != null &&
                     ProjectName.Equals(other.ProjectName)
                 ) &&
                 (
                     PrimaryContact == other.PrimaryContact ||
                     PrimaryContact != null &&
                     PrimaryContact.Equals(other.PrimaryContact)
                 ) &&
                 (
                     Status == other.Status ||
                     Status != null &&
                     Status.Equals(other.Status)
                 ) &&
                 (
                     ProjectId == other.ProjectId ||
                     ProjectId != null &&
                     ProjectId.Equals(other.ProjectId)
                 ) &&
                 (
                     ExpectedStartDate == other.ExpectedStartDate ||
                     ExpectedStartDate != null &&
                     ExpectedStartDate.Equals(other.ExpectedStartDate)
                 ) &&
                 (
                     ExpectedEndDate == other.ExpectedEndDate ||
                     ExpectedEndDate != null &&
                     ExpectedEndDate.Equals(other.ExpectedEndDate)
                 ));
        }
示例#20
0
        public IActionResult Create(RegistrationDto registrationDto)
        {
            PrimaryContact primaryContact = registrationDto.PrimaryContact;
            Event          vmEvent        = _context.Events
                                            .Where(e => e.Id == registrationDto.Event.Id)
                                            .Include(e => e.Registrations)
                                            .ThenInclude(r => r.Registrant)
                                            .First();

            // Add primary contact if necessary
            if (!_context.PrimaryContacts.Any(pc => pc.Name.Equals(primaryContact.Name) &&
                                              pc.EmailAddress.Equals(primaryContact.EmailAddress) &&
                                              pc.PhoneNumber.Equals(primaryContact.PhoneNumber)))
            {
                _context.PrimaryContacts.Add(primaryContact);
                _context.SaveChanges();
            }
            else
            {
                primaryContact = _context.PrimaryContacts
                                 .Where(pc => pc.Name.Equals(registrationDto.PrimaryContact.Name))
                                 .FirstOrDefault();
            }

            // Iterate over registrants
            registrationDto.Registrants.ForEach(reg =>
            {
                Registrant registrant = new Registrant
                {
                    Name = reg.Name
                };
                bool isWaitList = false;

                // Add registrant if necessary
                if (!_context.Registrants.Any(r => r.Name.Equals(registrant.Name)))
                {
                    _context.Registrants.Add(registrant);
                    _context.SaveChanges();
                }
                else
                {
                    registrant = _context.Registrants
                                 .Where(r => r.Name.Equals(reg.Name))
                                 .FirstOrDefault();
                }

                if (vmEvent.Registrations.Where(r => !r.IsWaitList).Count()
                    >= vmEvent.Capacity)
                {
                    isWaitList = true;
                }

                // Create registration
                Registration registration = new Registration
                {
                    Event           = vmEvent,
                    PrimaryContact  = primaryContact,
                    Registrant      = registrant,
                    HasPhotoRelease = reg.PhotoRelease,
                    IsWaitList      = isWaitList
                };

                // Add registration if it doesn't already exist
                if (vmEvent.Registrations == null ||
                    vmEvent.Registrations.Count == 0 ||
                    !vmEvent.Registrations.Any(r => r.Registrant.Name.Equals(registration.Registrant.Name)))
                {
                    _context.Registrations.Add(registration);
                    _context.SaveChanges();
                }
            });

            return(CreatedAtRoute("GetAll", null));
        }