public AmendmentOutcome BuildAmendments(Amendment amendment)
        {
            using (var context = new CrmServiceContext(_organizationService))
            {
                AmendmentOutcome outcome;

                var amendmentDto = new rscd_Amendment
                {
                    rscd_Checkingwindow = amendment.CheckingWindow.ToCRMCheckingWindow(),
                    rscd_Amendmenttype  = amendment.AmendmentType.ToCRMAmendmentType(),
                    rscd_Academicyear   = _allocationYear,
                    rscd_URN            = amendment.URN,
                    OwnerId             = _firstLineTeam
                };

                outcome = _outcomeService.ApplyRules(amendmentDto, amendment);

                if (amendment.IsUserConfirmed && outcome.IsComplete && outcome.FurtherQuestions == null)
                {
                    MapAmendmentToDto(amendment, amendmentDto);
                    var amendmentTypeEntity = MapAmendmentTypeToDto(amendment);
                    context.AddObject(amendmentTypeEntity);
                    context.AddObject(amendmentDto);

                    // Save
                    var result = context.SaveChanges();
                    if (result.HasError)
                    {
                        throw result.FirstOrDefault(e => e.Error != null)?.Error ?? new ApplicationException();
                    }

                    if (amendmentDto.rscd_Outcome == rscd_Outcome.Autoapproved ||
                        amendmentDto.rscd_Outcome == rscd_Outcome.Autorejected)
                    {
                        amendmentDto.StateCode        = rscd_AmendmentState.Inactive;
                        amendmentDto.rscd_recorded_by = _autoRecordedUser;
                        _organizationService.Update(amendmentDto);
                    }

                    var relationship = new Relationship(RelationshipKey);
                    _organizationService.Associate(amendmentTypeEntity.LogicalName, amendmentTypeEntity.Id, relationship,
                                                   new EntityReferenceCollection
                    {
                        new EntityReference(amendmentDto.LogicalName, amendmentDto.Id)
                    });

                    outcome.IsAmendmentCreated = true;
                    outcome.NewAmendmentId     = amendmentDto.Id;

                    _logger.LogInformation("Amendment requested - ID: {amendmentId}", amendmentDto.Id);
                }

                return(outcome);
            }
        }
        private rscd_Establishment GetOrCreateEstablishment(CheckingWindow checkingWindow, string id)
        {
            using (var context = new CrmServiceContext(_organizationService))
            {
                var establishmentDto =
                    context.rscd_EstablishmentSet.SingleOrDefault(
                        e => e.rscd_URN == id);
                if (establishmentDto == null)
                {
                    establishmentDto =
                        context.rscd_EstablishmentSet.SingleOrDefault(
                            e => e.rscd_LAEstab == id);
                }

                if (establishmentDto != null)
                {
                    return(establishmentDto);
                }

                School establishment = null;
                try
                {
                    establishment = _establishmentService.GetByURN(checkingWindow, new URN(id));
                }
                catch
                {
                }

                if (establishment == null)
                {
                    establishment = _establishmentService.GetByDFESNumber(checkingWindow, id);
                }

                if (establishment == null)
                {
                    return(null);
                }


                establishmentDto = new rscd_Establishment()
                {
                    rscd_Name               = establishment.SchoolName,
                    rscd_URN                = establishment.Urn.Value,
                    rscd_LAEstab            = establishment.DfesNumber.ToString(),
                    rscd_Schooltype         = establishment.SchoolType,
                    rscd_NumberofAmendments = 0
                };
                context.AddObject(establishmentDto);
                var result = context.SaveChanges();
                if (result.HasError)
                {
                    throw result.FirstOrDefault(e => e.Error != null)?.Error ?? new ApplicationException();
                }

                return(establishmentDto);
            }
        }
コード例 #3
0
        public void Create(string name)
        {
            var account = new Account()
            {
                Name = name
            };

            context.AddObject(account);
            context.SaveChanges();
        }
コード例 #4
0
ファイル: OpportunityTools.cs プロジェクト: gothandy/Augustus
        public void Create(string name, Account account)
        {
            var entRef = new EntityReference("account", account.Id);

            var entity = new Opportunity()
            {
                Name = name, CustomerId = entRef
            };

            context.AddObject(entity);
            context.SaveChanges();
        }
コード例 #5
0
        public IHttpActionResult Create(
            VolunteerApplicationRequest volunteerApplicationRequest)
        {
            csc_VolunteerApplication volunteerApplicationEntity;

            if (volunteerApplicationRequest.Id != null)
            {
                // attached to context
                volunteerApplicationEntity = this.GetVolunteerApplicationEntity(
                    volunteerApplicationRequest.Id ?? Guid.Empty,
                    User.Identity.GetVolunteerId());

                if (volunteerApplicationEntity.StatusCodeEnum != csc_VolunteerApplication_StatusCode.Draft &&
                    volunteerApplicationEntity.StatusCodeEnum != csc_VolunteerApplication_StatusCode.Submitted)
                {
                    return(Content(HttpStatusCode.BadRequest, new WebApiErrorResponse
                    {
                        Message = "The request is invalid.",
                        Data = "Volunteer Application StatusCode should be Daft or InProgress"
                    }));
                }

                _mapper.Map(volunteerApplicationRequest, volunteerApplicationEntity);

                _ctx.UpdateObject(volunteerApplicationEntity);

                _ctx.SaveChanges();
            }
            else
            {
                volunteerApplicationEntity = new csc_VolunteerApplication();

                _ctx.AddObject(volunteerApplicationEntity);

                volunteerApplicationEntity.csc_Volunteer =
                    new EntityReference(csc_Volunteer.EntityLogicalName, User.Identity.GetVolunteerId());

                _mapper.Map(volunteerApplicationRequest, volunteerApplicationEntity);

                _ctx.SaveChanges();
            }

            // todo just return the id
            return(Ok(new WebApiSuccessResponse <VolunteerApplicationResponse>
            {
                Data = _mapper.Map <VolunteerApplicationResponse>(volunteerApplicationEntity)
            }));
        }
 public bool CreateConfirmationRecord(ConfirmationRecord confirmationRecord)
 {
     using (var context = new CrmServiceContext(_organizationService))
     {
         var confirmation = new new_reviewandconfirmschool
         {
             new_UserID    = confirmationRecord.UserId,
             new_SchoolURN = confirmationRecord.EstablishmentId,
             new_Reviewed  = confirmationRecord.ReviewCompleted,
             new_Confirmed = confirmationRecord.DataConfirmed
         };
         context.AddObject(confirmation);
         context.SaveChanges();
         return(true);
     }
 }
コード例 #7
0
        public override Task <TUser> FindAsync(UserLoginInfo login)
        {
            Log.Logger.Information("PortalUserStore.FindAsync");

            var queryable = from cscPortalUser in _ctx.csc_PortalUserSet
                            join cscVolunteer in _ctx.csc_VolunteerSet on cscPortalUser.csc_Volunteer.Id equals cscVolunteer.Id
                            into gj
                            from cscVolunteer in gj.DefaultIfEmpty()
                            where cscPortalUser.csc_ProviderKey.Contains(login.ProviderKey)
                            where cscPortalUser.csc_LoginProvider.Contains(login.LoginProvider)
                            select new { cscPortalUser, cscVolunteer };

            var result = queryable.FirstOrDefault();

            csc_PortalUser portalUserEntity;
            csc_Volunteer  volunteerEntity;

            if (result != null)
            {
                portalUserEntity = result.cscPortalUser;
                volunteerEntity  = result.cscVolunteer;
                _ctx.Attach(portalUserEntity);
                portalUserEntity.csc_LoginOn = DateTime.Now.ToUniversalTime();
                _ctx.UpdateObject(portalUserEntity);
                _ctx.SaveChanges();
            }
            else
            {
                portalUserEntity = new csc_PortalUser();
                volunteerEntity  = new csc_Volunteer();
                _ctx.AddObject(portalUserEntity);
                portalUserEntity.csc_LoginProvider = login.LoginProvider;
                portalUserEntity.csc_ProviderKey   = login.ProviderKey;
                portalUserEntity.csc_LoginOn       = DateTime.Now.ToUniversalTime();
                _ctx.SaveChanges();
            }

            var portalUser = _mapper.Map <PortalUser>(portalUserEntity);

            portalUser.Volunteer = _mapper.Map <Volunteer>(volunteerEntity);

            return(Task.FromResult(portalUser as TUser));
        }
コード例 #8
0
        public WebApiSuccessResponse Save(List <VolunteerReferenceRequest> volunteerReferences)
        {
            foreach (var volunteerReference in volunteerReferences)
            {
                if (volunteerReference.Id != null && volunteerReference.Id != Guid.Empty)
                {
                    continue;
                }

                var volunteerEntity = _mapper.Map <csc_VolunteerReference>(volunteerReference);

                volunteerEntity.csc_Volunteer =
                    new EntityReference(csc_Volunteer.EntityLogicalName, User.Identity.GetVolunteerId());

                _ctx.AddObject(volunteerEntity);
            }

            var queryable = from volunteerReferenceEntity in _ctx.csc_VolunteerReferenceSet
                            where volunteerReferenceEntity.csc_Volunteer.Id.Equals(User.Identity.GetVolunteerId())
                            select volunteerReferenceEntity;

            var volunteerReferenceEntities = queryable.ToList();

            foreach (var volunteerReferenceEntity in volunteerReferenceEntities)
            {
                var foundVolunteerReference =
                    volunteerReferences.SingleOrDefault(req => req.Id == volunteerReferenceEntity.Id);

                if (foundVolunteerReference != null)
                {
                    _ctx.UpdateObject(_mapper.Map(foundVolunteerReference, volunteerReferenceEntity));
                }
                else
                {
                    _ctx.DeleteObject(volunteerReferenceEntity);
                }
            }

            _ctx.SaveChanges();

            return(new WebApiSuccessResponse());
        }