Example #1
0
        public ServiceCallResult <RequestViewModel> UpdateRequest([FromBody] RequestViewModel request)
        {
            try
            {
                string previousStatus     = "";
                bool   owningStreamChange = false;
                bool   statusChange       = false;
                _wtContext.SetCurrentUser(Auth.GetCurrentUser(User.Identity.Name).fullName);
                if (!isRequestValid(request))
                {
                    return(ServiceCallResult <RequestViewModel> .CreateErrorResult(String.Format(UserMessageResource.ErrorSavingInputInvalid, FieldNamesResource.Request, FieldNamesResource.Fields), request));
                }

                var existingRequest = _wtContext.Requests.Include(x => x.Status).Include(x => x.OwningStream).Where(x => x.Id == request.Id).FirstOrDefault();
                if (existingRequest != null)
                {
                    existingRequest.ApplicationId = request.AppName.Id;
                    existingRequest.ProjectName   = request.ProjectName;
                    existingRequest.Problem       = request.Problem;
                    existingRequest.BenefitCase   = request.BenefitCase;
                    existingRequest.COEPriority   = request.COEPriority;
                    existingRequest.GBSPriority   = request.GBSPriority;
                    if (request.StatusId != existingRequest.StatusId)
                    {
                        previousStatus           = existingRequest.Status.Name;
                        existingRequest.StatusId = request.StatusId;
                    }
                    existingRequest.MD_50_DueDate = request.MD_50_DueDate != null?Convert.ToDateTime(request.MD_50_DueDate) : (DateTime?)null;

                    existingRequest.MD_70_DueDate = request.MD_70_DueDate != null?Convert.ToDateTime(request.MD_70_DueDate) : (DateTime?)null;

                    existingRequest.TestingDate = request.TestingDate != null?Convert.ToDateTime(request.TestingDate) : (DateTime?)null;

                    existingRequest.ProductionDate = request.ProductionDate != null?Convert.ToDateTime(request.ProductionDate) : (DateTime?)null;

                    existingRequest.TotalEstimate             = request.TotalEstimate;
                    existingRequest.OracleDevEstimateOffShore = request.OracleDevEstimateOffShore;
                    existingRequest.OracleDevEstimateOnShore  = request.OracleDevEstimateOnShore;
                    existingRequest.DCOEEstimate             = request.DCOEEstimate;
                    existingRequest.CRNo                     = request.CRNo;
                    existingRequest.FunctionalContact        = request.FunctionalContact;
                    existingRequest.BIContact                = request.BIContact;
                    existingRequest.OracleDevelopmentLead    = request.OracleDevelopmentLead;
                    existingRequest.DCOEDevelopmentLead      = request.DCOEDevelopmentLead;
                    existingRequest.MD_50                    = request.MD_50;
                    existingRequest.MD_70                    = request.MD_70;
                    existingRequest.TIPUrl                   = request.TIPUrl;
                    existingRequest.EBSGateQuestionnaireUrl  = request.EBSGateQuestionnaireUrl;
                    existingRequest.BIGateQuestionnaireUrl   = request.BIGateQuestionnaireUrl;
                    existingRequest._NETGateQuestionnaireUrl = request._NETGateQuestionnaireUrl;
                    existingRequest.OTMGateQuestionnaireUrl  = request.OTMGateQuestionnaireUrl;
                    existingRequest.ReadyForEBSGateId        = request.ReadyForEBSGate != null ? request.ReadyForEBSGate.Id : (int?)null;
                    existingRequest.EBSGateStatusId          = request.EBSGateStatus != null ? request.EBSGateStatus.Id : (int?)null;
                    existingRequest.NextEBSGateId            = request.NextEBSGate != null ? request.NextEBSGate.Id : (int?)null;
                    existingRequest.ReadyForOTMGateId        = request.ReadyForOTMGate != null ? request.ReadyForOTMGate.Id : (int?)null;
                    existingRequest.OTMGateStatusId          = request.OTMGateStatus != null ? request.OTMGateStatus.Id : (int?)null;
                    existingRequest.OTMEBSGateId             = request.OTMEBSGate != null ? request.OTMEBSGate.Id : (int?)null;
                    existingRequest.ReadyForBIGateId         = request.ReadyForBIGate != null ? request.ReadyForBIGate.Id : (int?)null;
                    existingRequest.BIGateStatusId           = request.BIGateStatus != null ? request.BIGateStatus.Id : (int?)null;
                    existingRequest.NextBIGateId             = request.NextBIGate != null ? request.NextBIGate.Id : (int?)null;
                    existingRequest.ReadyFor_NETGateId       = request.ReadyFor_NETGate != null ? request.ReadyFor_NETGate.Id : (int?)null;
                    existingRequest._NETGateStatusId         = request._NETGateStatus != null ? request._NETGateStatus.Id : (int?)null;
                    existingRequest.Next_NETGateId           = request.Next_NETGate != null ? request.Next_NETGate.Id : (int?)null;
                    existingRequest.EstimateInfra            = request.EstimateInfra;
                    existingRequest.FrontLineContact         = request.FrontLineContact;
                    existingRequest.OwningSiteId             = request.OwningSite != null ? request.OwningSite.Id : (int?)null;

                    existingRequest.Requestor               = request.Requestor;
                    existingRequest.BIRequestId             = request.BIRequestId;
                    existingRequest.OriginalSystemReference = request.OriginalSystemReference;
                    existingRequest.Attribute1              = request.Attribute1;
                    existingRequest.Attribute2              = request.Attribute2;
                    existingRequest.Attribute3              = request.Attribute3;
                    existingRequest.Attribute4              = request.Attribute4;
                    existingRequest.Attribute5              = request.Attribute5;
                    existingRequest.Attribute6              = request.Attribute6;
                    existingRequest.Attribute7              = request.Attribute7;
                    existingRequest.Attribute8              = request.Attribute8;
                    existingRequest.Attribute9              = request.Attribute9;
                    existingRequest.Attribute10             = request.Attribute10 != null?Convert.ToDateTime(request.Attribute10) : (DateTime?)null;

                    //default these values to false, set them to true whether values exist in impacted stream array.
                    existingRequest.BIImpactedStream  = false;
                    existingRequest.OTMImpactedStream = false;

                    //Change Valid
                    if (existingRequest.StatusId != request.Status.Id)
                    {
                        statusChange             = true;
                        existingRequest.StatusId = request.Status.Id;
                    }

                    if (existingRequest.OwningStreamId != request.OwningStream.Id)
                    {
                        owningStreamChange             = true;
                        existingRequest.OwningStreamId = request.OwningStream.Id;
                    }

                    //regions
                    var regions = _wtContext.RequestRegions.Where(x => x.RequestId == request.Id).ToList();
                    _wtContext.RequestRegions.RemoveRange(regions);
                    foreach (var r in request.Regions)
                    {
                        var reg = new RequestRegion();
                        reg.RequestId = request.Id;
                        reg.RegionId  = r.Id;
                        _wtContext.RequestRegions.Add(reg);
                    }

                    //sbus
                    var sbus = _wtContext.RequestSBUs.Where(x => x.RequestId == request.Id).ToList();
                    _wtContext.RequestSBUs.RemoveRange(sbus);
                    foreach (var s in request.SBUs)
                    {
                        var sbu = new RequestSBU();
                        sbu.RequestId = request.Id;
                        sbu.SBUId     = s.Id;
                        _wtContext.RequestSBUs.Add(sbu);
                    }
                    //impactedstreams
                    var impactedstreams = _wtContext.RequestImpactedStreams.Where(x => x.RequestId == request.Id).ToList();
                    _wtContext.RequestImpactedStreams.RemoveRange(impactedstreams);
                    foreach (var i in request.ImpactedStreams)
                    {
                        var ist = new RequestImpactedStream();
                        ist.RequestId        = request.Id;
                        ist.ImpactedStreamId = i.Id;
                        if (i.Name.ToUpper() == "BI")
                        {
                            existingRequest.BIImpactedStream = true;
                        }
                        if (i.Name.ToUpper() == "OTM")
                        {
                            existingRequest.OTMImpactedStream = true;
                        }

                        _wtContext.RequestImpactedStreams.Add(ist);
                    }
                    //modules
                    var modules = _wtContext.RequestModules.Where(x => x.RequestId == request.Id).ToList();
                    _wtContext.RequestModules.RemoveRange(modules);
                    foreach (var i in request.Modules)
                    {
                        var mod = new RequestModule();
                        mod.RequestId = request.Id;
                        mod.ModuleId  = i.Id;
                        _wtContext.RequestModules.Add(mod);
                    }
                    //developmentteams
                    var developmentteams = _wtContext.RequestDevelopmentTeams.Where(x => x.RequestId == request.Id).ToList();
                    _wtContext.RequestDevelopmentTeams.RemoveRange(developmentteams);
                    foreach (var i in request.DevelopmentTeams)
                    {
                        var dt = new RequestDevelopmentTeam();
                        dt.RequestId         = request.Id;
                        dt.DevelopmentTeamId = i.Id;
                        _wtContext.RequestDevelopmentTeams.Add(dt);
                    }
                    //oraclepreprodenvironments
                    var oracleenvs = _wtContext.RequestOraclePreProdEnvironments.Where(x => x.RequestId == request.Id).ToList();
                    _wtContext.RequestOraclePreProdEnvironments.RemoveRange(oracleenvs);
                    foreach (var i in request.OraclePreProdEnvironments)
                    {
                        var oe = new RequestOraclePreProdEnvironment();
                        oe.RequestId = request.Id;
                        oe.OraclePreProdEnvironmentId = i.Id;
                        _wtContext.RequestOraclePreProdEnvironments.Add(oe);
                    }

                    //add note if status has changed
                    if (!string.IsNullOrEmpty(previousStatus))
                    {
                        var note = new RequestNote();
                        note.RequestId = request.Id;
                        note.Note      = "Status Changed from " + previousStatus + " to " + request.Status.Name;
                        _wtContext.RequestNotes.Add(note);
                    }
                    //attachments

                    _wtContext.SaveChanges();
                }
                else
                {
                    return(ServiceCallResult <RequestViewModel> .CreateErrorResult(String.Format(UserMessageResource.ErrorSavingInputInvalid, FieldNamesResource.Request, FieldNamesResource.Fields), request));
                }
                Request ret = _wtContext.Requests.Where(x => x.Id == request.Id)
                              .Include(x => x.Application)
                              .Include(x => x.Attachments)
                              .Include(x => x.Status)
                              .Include(x => x.Regions).ThenInclude(x => x.Region)
                              .Include(x => x.SBUs).ThenInclude(x => x.SBU)
                              .Include(x => x.OwningSite)
                              .Include(x => x.OwningStream)
                              .Include(x => x.ImpactedStreams).ThenInclude(x => x.ImpactedStream)
                              .Include(x => x.Modules).ThenInclude(x => x.Module)
                              .Include(x => x.DevelopmentTeams).ThenInclude(x => x.DevelopmentTeam)
                              .Include(x => x.OraclePreProdEnvironments).ThenInclude(x => x.OraclePreProdEnvironment)
                              .Include(x => x.BIRequest)
                              .Include(x => x.BIGateStatus)
                              .Include(x => x.NextBIGate)
                              .Include(x => x.ReadyForBIGate)
                              .Include(x => x._NETGateStatus)
                              .Include(x => x.Next_NETGate)
                              .Include(x => x.ReadyFor_NETGate)
                              .Include(x => x.EBSGateStatus)
                              .Include(x => x.NextEBSGate)
                              .Include(x => x.ReadyForEBSGate)
                              .Include(x => x.OTMGateStatus)
                              .Include(x => x.OTMEBSGate)
                              .Include(x => x.ReadyForOTMGate).FirstOrDefault();

                OwningStream owningStream = _wtContext.OwningStreams.Where(n => n.Id == request.OwningStream.Id).FirstOrDefault();
                string       email        = string.Empty;

                if (owningStream != null)
                {
                    email = owningStream.dlEmailAddress;
                }

                //Send Notifications
                if (statusChange)
                {
                    string title = "New Oracle COE Request Logged";
                    sendNotificationEmail(ret, EmailType.OwningStreamChange, title, email);
                }

                if (owningStreamChange)
                {
                    string title = "New Oracle COE Request Logged";
                    sendNotificationEmail(ret, EmailType.OwningStreamChange, title, email);
                }

                var vm = Mappers <Request, RequestViewModel> .MapToViewModel(ret);

                return(ServiceCallResult <RequestViewModel> .CreateSuccessResult(string.Format(UserMessageResource.FieldSavedSuccessfully, FieldNamesResource.Request), vm));
            }
            catch (Exception ex)
            {
                return(ServiceCallResult <RequestViewModel> .CreateErrorResult(string.Format(UserMessageResource.ErrorAddingField, FieldNamesResource.Request) + ex.Message, new RequestViewModel()));
            }
        }
Example #2
0
        public ServiceCallResult <AddRequestViewModel> AddRequest([FromBody] AddRequestViewModel request)
        {
            try
            {
                _wtContext.SetCurrentUser(Auth.GetCurrentUser(User.Identity.Name).fullName);
                if (!isRequestValid(request))
                {
                    return(ServiceCallResult <AddRequestViewModel> .CreateErrorResult(String.Format(UserMessageResource.ErrorSavingInputInvalid, FieldNamesResource.Request, FieldNamesResource.Fields), request));
                }
                Request newRequest = new Request();
                newRequest.ApplicationId           = request.AppName.Id;
                newRequest.ProjectName             = request.ProjectName;
                newRequest.Problem                 = request.Problem;
                newRequest.BenefitCase             = request.BenefitCase;
                newRequest.BIRequestId             = request.BiRequestId;
                newRequest.OriginalSystemReference = request.OriginalSystemReference;
                newRequest.Requestor               = request.Requestor;
                if (request.OwningSite != null && request.OwningSite.Id != 0)
                {
                    newRequest.OwningSiteId = request.OwningSite.Id;
                }
                newRequest.OwningStreamId = request.OwningStream.Id;
                newRequest.StatusId       = _wtContext.Statuses.Where(x => x.Name.ToLower() == "new" && x.DeleteMark == false).FirstOrDefault().Id;
                int no = _wtContext.BooleanDropDownValues.Where(x => x.Name.ToLower() == "no").FirstOrDefault().Id;
                newRequest.ReadyForBIGateId   = no;
                newRequest.ReadyForEBSGateId  = no;
                newRequest.ReadyForOTMGateId  = no;
                newRequest.ReadyFor_NETGateId = no;

                _wtContext.Requests.Add(newRequest);
                _wtContext.SaveChanges();

                Request addedRequest = _wtContext.Requests
                                       .Where(x => x.ProjectName == request.ProjectName)
                                       .OrderByDescending(y => y.CreatedOn)
                                       .Include(i => i.OwningStream)
                                       .Include(i => i.OwningSite)
                                       .FirstOrDefault();

                if (addedRequest != null)
                {
                    //add Regions
                    foreach (var r in request.Regions)
                    {
                        var reg = new RequestRegion();
                        reg.RequestId = addedRequest.Id;
                        reg.RegionId  = r.Id;
                        //reg.Region = Mappers<Region, RegionViewModel>.MapToEntity(r);
                        _wtContext.RequestRegions.Add(reg);
                    }
                    //add SBUs
                    foreach (var s in request.SBUs)
                    {
                        var sbu = new RequestSBU();
                        sbu.RequestId = addedRequest.Id;
                        sbu.SBUId     = s.Id;
                        //sbu.SBU = Mappers<SBU, SBUViewModel>.MapToEntity(s);
                        _wtContext.RequestSBUs.Add(sbu);
                    }
                    //add attachments

                    _wtContext.SaveChanges();
                }

                Request ret = _wtContext.Requests
                              .Where(x => x.ProjectName == request.ProjectName)
                              .Include(x => x.OwningStream)
                              .Include(x => x.BIRequest)
                              .OrderByDescending(y => y.CreatedOn)
                              .FirstOrDefault();
                var vm = Mappers <Request, AddRequestViewModel> .MapToViewModel(ret);

                string title = "New Oracle COE Request Logged";
                sendNotificationEmail(ret, EmailType.NewRequestAdded, title, string.Empty);
                return(ServiceCallResult <AddRequestViewModel> .CreateSuccessResult(String.Format(UserMessageResource.FieldAddedSuccessfully, FieldNamesResource.Request), vm));
            }
            catch (Exception ex)
            {
                return(ServiceCallResult <AddRequestViewModel> .CreateErrorResult(String.Format(UserMessageResource.ErrorAddingField, FieldNamesResource.Request) + ex.Message, new AddRequestViewModel()));
            }
        }