예제 #1
0
        public async Task <OpportunityAuthResponse> Create(OpportunityCreateRequest request, IUser user)
        {
            var toSave = _mapper.Map <Opportunity>(request);

            toSave.OpportunityUser.Add(new OpportunityUser {
                UserId = user.Id
            });
            toSave.Agency = user.Agency;
            if (request.IsPosting)
            {
                toSave.PublishedAt = DateTime.UtcNow;
            }
            var saved = await _opportunityService.Create(toSave, user);

            if (request.IsPosting)
            {
                if (user.EmailVerified == false)
                {
                    throw new UnauthorizedAccessException();
                }
                toSave.PublishedAt = DateTime.UtcNow;
                saved = await _opportunityService.Update(toSave, user);
            }
            var result = _mapper.Map <OpportunityAuthResponse>(saved);

            return(result);
        }
        public IActionResult Update(string id, [FromBody] OpportunityDetails opportunityDetailsIn)
        {
            id = id.ToLower();

            OpportunityResponse.Success = false;

            if (opportunityDetailsIn == null)
            {
                OpportunityResponse.Message = "Opportunity submitted was null";
                return(BadRequest(new[] { OpportunityResponse }));
            }

            try
            {
                var existing = _opportunitiesService.Get(id);

                if (existing == null)
                {
                    OpportunityResponse.Message = "Opportunity record not found";
                    return(NotFound(new[] { OpportunityResponse }));
                }

                var updated          = _opportunitiesService.Update(id, opportunityDetailsIn);
                var opportunityFound = new List <Opportunity>()
                {
                    _opportunitiesService.Get(id)
                };

                OpportunityResponse.Data = opportunityFound;
                if (!updated)
                {
                    OpportunityResponse.NumberOfRecordsFound = opportunityFound.Count;
                    OpportunityResponse.Message = "Update didn't work!";
                    return(BadRequest(new[] { OpportunityResponse }));
                }

                OpportunityResponse.Success = true;
                OpportunityResponse.NumberOfRecordsFound = opportunityFound.Count;
                OpportunityResponse.Message = "Opportunity record updated";
                return(Ok(new[] { OpportunityResponse }));
            }

            catch (MongoException ex)
            {
                _logger.LogError($"Error updating opportunity record in the DB: {ex.Message}");
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error: {ex.Message}");
            }
            _logger.LogError("Error: update request cannot be handled, bad request");
            return(BadRequest());
        }
예제 #3
0
        public HttpResponseMessage Update(OpportunityUpdateRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            _opportunity.Update(model);

            SuccessResponse response = new SuccessResponse();

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
        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));
            }
        }
예제 #5
0
 public ActionResult Edit(OpportunityViewModel opportunity)
 {
     if (ModelState.IsValid)
     {
         var entity = Mapper.Map <Opportunity>(opportunity);
         opportunityService.Update(entity);
         return(RedirectToAction("Index"));
     }
     ViewBag.CampaignSourceId = new SelectList(campaignSourceService.GetAll(), "Id", "Name");
     ViewBag.CompanyId        = new SelectList(companyService.GetAll(), "Id", "Owner");
     ViewBag.ContactId        = new SelectList(contactService.GetAll(), "Id", "Owner");
     ViewBag.LeadSourceId     = new SelectList(leadSourceService.GetAll(), "Id", "Name");
     return(View(opportunity));
 }