Exemplo n.º 1
0
        public Result UpdateCriterion(JobListingCriteriaEntity criterion)

        /*
         * Update one Answer entry
         * Currently a wrapper of insert Answer as they can do both at once.
         */
        {
            Result result = new Result();

            //TODO:

            try
            {
                result = InsertCriterion(criterion);
                return(result);
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
                result.Success = false;
                result.Message = ex.Message;
            }

            return(result);
        }
        public HttpResponseMessage PutCriteria_V1([FromBody] ListingCriteriaModel listingCriteriaModel)
        {
            var result = new Result();

            //Employer vertification
            object objemployer = null;

            Request.Properties.TryGetValue("employer", out objemployer);
            if (objemployer == null)
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, new Result(false)));
            }
            var employer = objemployer as EmployerEntity;

            if (employer.EmployerId != listingCriteriaModel.EmmployerId)
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, new Result(false)));
            }


            var timestamp = DateTime.Now;

            var ListingCriteria = new List <JobListingCriteriaEntity>();


            foreach (KeyValuePair <int, AnswerEntity> entry in listingCriteriaModel.Answers)
            {
                int          aspectId = entry.Key;
                AnswerEntity answer   = entry.Value;

                var listingCriterion = new JobListingCriteriaEntity();
                listingCriterion.AspectId     = aspectId;
                listingCriterion.QuestionId   = answer.QuestionId;
                listingCriterion.AnswerId     = answer.AnswerId;
                listingCriterion.Value        = answer.Value;
                listingCriterion.LastUpdate   = timestamp;
                listingCriterion.JobListingId = listingCriteriaModel.JobListingId;

                ListingCriteria.Add(listingCriterion);
            }

            result = _jobListingCriteriaManager.InsertCriteria(ListingCriteria);

            if (!result.Success)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, result));
            }

            result.Message = " Criteria updated successfully";
            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
Exemplo n.º 3
0
        public Result InsertCriterion(JobListingCriteriaEntity criterion)

        /*
         * Insert one answer (one aspect) into the database
         *
         */

        {
            Result result = new Result();

            //TODO:
            try
            {
                var con   = new DapperConnectionManager();
                var query = new QueryEntity();
                if (criterion == null)
                {
                    result         = null;
                    result.Success = false;
                    result.Message = "Login error";
                    return(result);
                }
                query.Entity = criterion;

                /* query.Entity = new { UserId = userId,
                 *   AspectId = answer.AspectId,
                 *  // AnswerId = answer.AnswerId,
                 *   Value = answer.Value
                 *
                 * };*/

                // check if there is any records exist if yes, update, else, insert
                // Assume that Listing ID and AspectID are enforced at the controller

                query.Query = @"
                BEGIN TRAN
                IF EXISTS (SELECT * FROM dbo.JobListingCriteria WHERE JobListingId = @JobListingId and AspectId = @AspectId )
                BEGIN
                    UPDATE dbo.JobListingCriteria SET Value = @Value , QuestionId = @QuestionId, AnswerId = @AnswerId , LastUpdate= @LastUpdate
                    WHERE JobListingId = @JobListingId and AspectId = @AspectId
                END 
                ELSE
                BEGIN 
                INSERT INTO dbo.JobListingCriteria (JobListingId, AspectId, Value, QuestionId, AnswerId, LastUpdate )
                                                    VALUES(@JobListingId, @AspectId, @Value, @QuestionId, @AnswerId, @LastUpdate)
                END
                COMMIT TRAN
";
                result      = con.ExecuteQuery <UsersQuizzesEntity>(query);

                return(result);
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
                result.Success = false;
                result.Message = ex.Message;
            }

            return(result);
        }