public HttpResponseMessage Post(HttpRequestMessage request, int projectId)
        {
            Project theProject = _service.GetProject(projectId);

            if (theProject == null)
            {
                return request.CreateResponse(HttpStatusCode.NotFound, "project not found");
            }

            int companyId = _service.GetUserProfile(_security.GetUserId(User.Identity.Name)).CompanyId;

            // get master bp because that is what gc's bid to.
            BidPackage bidPackage = theProject.BidPackages.Where(x => x.IsMaster).SingleOrDefault();

            Invitation selfInvite = _service.Get(bidPackage.Id, companyId);

            if (selfInvite != null && selfInvite.InvitationType == InvitationType.SentFromCreatedBy)
            {
                return request.CreateResponse(HttpStatusCode.Conflict, "company was invited. must respond to invitation.");
            }
            else if (selfInvite != null && selfInvite.InvitationType == InvitationType.SelfInvite && selfInvite.AcceptedDate.HasValue)
            {
                return request.CreateResponse(HttpStatusCode.Conflict, "company has already joined project.");
            }
            else if (selfInvite != null && selfInvite.InvitationType == InvitationType.SelfInvite && selfInvite.RejectedDate.HasValue)
            {
                selfInvite.RejectedDate = default(DateTime?);
                selfInvite.AcceptedDate = DateTime.Now;

                if (_service.Update(selfInvite))
                {
                    _notice.SendInviteResponse(bidPackage.Id);
                    return request.CreateResponse(HttpStatusCode.OK, new { date = selfInvite.AcceptedDate.Value.ToShortDateString() });
                }
            }
            else
            {
                selfInvite = new Invitation
                {
                    AcceptedDate = DateTime.Now,
                    BidPackageId = bidPackage.Id,
                    SentToId = companyId,
                    InvitationType = InvitationType.SelfInvite,
                    SentDate = DateTime.Now
                };

                if (_service.Create(selfInvite))
                {
                    _notice.SendInviteResponse(bidPackage.Id);
                    return request.CreateResponse(HttpStatusCode.OK, new { date = selfInvite.AcceptedDate.Value.ToShortDateString() });
                }
            }

            return request.CreateResponse(HttpStatusCode.InternalServerError);
        }
Ejemplo n.º 2
0
 public void UpdateInvitation(Invitation invite)
 {
     var current = _invites.Find(invite.BidPackageId, invite.SentToId);
     _context.Entry<Invitation>(current).CurrentValues.SetValues(invite);
 }