public async Task <IActionResult> Update([FromBody] UpdateOpportunityRequest opportunity, int id)
        {
            opportunity.id = id;
            var updatedOpportunity = await _opportunityService.Update(opportunity);

            if (updatedOpportunity != null)
            {
                return(Response(updatedOpportunity, 200));
            }
            else
            {
                return(Response(code: 400));
            }
        }
Esempio n. 2
0
        public UpdateOpportunityResponse UpdateOpportunity(UpdateOpportunityRequest request)
        {
            Logger.Current.Verbose("Request for updating an opportunity");
            request.opportunityViewModel.IsDeleted = false;
            var opportunityViewModel = request.opportunityViewModel;

            hasAccess(request.opportunityViewModel.OpportunityID, request.RequestedBy, request.AccountId, request.RoleId);
            if (request.opportunityViewModel.Image != null)
            {
                SaveImageResponse imageResponse = imageService.SaveImage(new SaveImageRequest()
                {
                    ImageCategory = ImageCategory.OpportunityProfile,
                    ViewModel     = request.opportunityViewModel.Image,
                    AccountId     = request.AccountId
                });
                request.opportunityViewModel.Image = imageResponse.ImageViewModel;
            }
            Opportunity opportunity         = Mapper.Map <OpportunityViewModel, Opportunity>(request.opportunityViewModel);
            bool        isOpportunityUnique = opportunityRepository.IsOpportunityUnique(opportunity);

            if (!isOpportunityUnique)
            {
                var message = "[|Opportunity with name|] \"" + opportunity.OpportunityName + "\" [|already exists.|]";
                throw new InvalidOperationException(message);
            }
            isOpportunityValid(opportunity);
            //opportunityRepository.Update(opportunity);
            // Opportunity updatedOpportunity = unitOfWork.Commit() as Opportunity;
            OpportunityTableType opportunityTableType = Mapper.Map <OpportunityViewModel, OpportunityTableType>(request.opportunityViewModel);
            OpportunityTableType newOpportunityType   = opportunityRepository.InsertOpportunity(opportunityTableType);
            // opportunityRepository.Insert(opportunity);
            Opportunity updatedOpportunity = opportunityRepository.FindBy(newOpportunityType.OpportunityID);

            if (indexingService.Update <Opportunity>(updatedOpportunity) > 0)
            {
                Logger.Current.Verbose("Opportunity updated to elasticsearch successfully");
            }
            if (request.opportunityViewModel.StageID != request.opportunityViewModel.PreviousStageID)
            {
                addToTopic(opportunityViewModel.OpportunityID, request.AccountId, opportunityViewModel.Contacts.Select(s => s.Id), opportunityViewModel.StageID);
            }

            return(new UpdateOpportunityResponse());
        }
Esempio n. 3
0
        public async Task <OpportunityResponse> Update(UpdateOpportunityRequest obj)
        {
            var opportunity = await _opportunityRepository.GetById(obj.id);

            if (opportunity == null)
            {
                Notify("Opportunity not found");
            }

            var user = await _userService.GetById(obj.UserId);

            if (user == null)
            {
                Notify("User not found");
            }

            var company = await _companyRepository.GetById(obj.CompanyId);

            if (company == null)
            {
                Notify("Company not found");
            }

            var classObj = await _classRepository.GetById(obj.ClassId);

            if (classObj == null)
            {
                Notify("Class not found");
            }
            if (!HasNotification())
            {
                var updateOpportunity = _mapper.Map(obj, opportunity);
                return(_mapper.Map <OpportunityResponse>(await _opportunityRepository.Update(updateOpportunity)));
            }
            else
            {
                return(null);
            }
        }