コード例 #1
0
        public async Task <ActionResult> ExtendDisabledCampaign([FromBody] JObject objJson)
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strMerchantId = MerchantLoginSessionKeys.GetMerchantIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strMerchantId))
                {
                    return(StatusCode(StatusCodes.Status403Forbidden, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                var objMerchantCampaignsDetails = _appDbContext.MerchantCampaigns
                                                  .Where(mc => mc.Id == Convert.ToInt32(objJson.SelectToken("merchantcampaignsid")) && mc.MerchantId == strMerchantId)
                                                  .OrderByDescending(t => t.Id).AsNoTracking().FirstOrDefault();

                if (objMerchantCampaignsDetails == null)
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Campaign doesn’t exist or Invalid Merchant." })));
                }

                if (Convert.ToBoolean(objMerchantCampaignsDetails.Active) == true)
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Campaign is active. You only extend/duplicate deactive campaign." })));
                }

                MerchantCampaigns objMerchantCampaigns = new MerchantCampaigns();
                objMerchantCampaigns.MerchantId      = strMerchantId;
                objMerchantCampaigns.Name            = objMerchantCampaignsDetails.Name;
                objMerchantCampaigns.Description     = objMerchantCampaignsDetails.Description;
                objMerchantCampaigns.Disclosure      = objMerchantCampaignsDetails.Disclosure;
                objMerchantCampaigns.CreatedDate     = DateTime.UtcNow;
                objMerchantCampaigns.StartDate       = Convert.ToDateTime(objJson.SelectToken("startdate"));
                objMerchantCampaigns.EndDate         = Convert.ToDateTime(objJson.SelectToken("enddate"));
                objMerchantCampaigns.StateProvinceID = objMerchantCampaignsDetails.StateProvinceID;
                objMerchantCampaigns.CityID          = objMerchantCampaignsDetails.CityID;
                objMerchantCampaigns.CountryID       = objMerchantCampaignsDetails.CountryID;
                objMerchantCampaigns.Active          = true;
                await _appDbContext.MerchantCampaigns.AddAsync(objMerchantCampaigns);

                int returnVal = await _appDbContext.SaveChangesAsync();

                if (returnVal > 0)
                {
                    return(Ok(new { Status = "OK", Detail = "Duplicate Merchant Campaign Created." }));
                }
                else
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support" })));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
コード例 #2
0
        public async Task <ActionResult> DisableMerchantCampaign([FromBody] JObject objJson)
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strMerchantId = MerchantLoginSessionKeys.GetMerchantIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strMerchantId))
                {
                    return(StatusCode(StatusCodes.Status403Forbidden, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                var objMerchantCampaignsDetails = _appDbContext.MerchantCampaigns
                                                  .Where(mc => mc.Id == Convert.ToInt32(objJson.SelectToken("merchantcampaignsid")) && mc.MerchantId == strMerchantId)
                                                  .OrderByDescending(t => t.Id).AsNoTracking().FirstOrDefault();

                if (objMerchantCampaignsDetails == null)
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Campaign doesn’t exist or Invalid Merchant." })));
                }

                MerchantCampaigns objMerchantCampaigns = new MerchantCampaigns();
                objMerchantCampaigns.Id     = Convert.ToInt32(objJson.SelectToken("merchantcampaignsid"));
                objMerchantCampaigns.Active = Convert.ToBoolean(Convert.ToInt32(objJson.SelectToken("activestatus")));

                _appDbContext.MerchantCampaigns.Attach(objMerchantCampaigns);
                _appDbContext.Entry(objMerchantCampaigns).Property("Active").IsModified = true;
                int returnVal = await _appDbContext.SaveChangesAsync();

                if (returnVal > 0)
                {
                    return(Ok(new { Status = "OK", Detail = "Merchant Campaign status has been updated." }));
                }
                else
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support" })));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }
コード例 #3
0
        public async Task <ActionResult> CreateMerchantCampaign([FromBody] JObject objJson)
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(Request.Headers["api_key"])))
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                string strMerchantId = MerchantLoginSessionKeys.GetMerchantIdByApiKey(_appDbContext, Guid.Parse(Request.Headers["api_key"]));
                if (string.IsNullOrEmpty(strMerchantId))
                {
                    return(StatusCode(StatusCodes.Status403Forbidden, (new { Status = "Error", Error = "Invalid ApiKey" })));
                }

                MerchantCampaigns objMerchantCampaigns = new MerchantCampaigns();
                objMerchantCampaigns.MerchantId      = strMerchantId;
                objMerchantCampaigns.Name            = Convert.ToString(objJson.SelectToken("name"));
                objMerchantCampaigns.Description     = Convert.ToString(objJson.SelectToken("description"));
                objMerchantCampaigns.Disclosure      = Convert.ToString(objJson.SelectToken("disclosure"));
                objMerchantCampaigns.CreatedDate     = DateTime.UtcNow;
                objMerchantCampaigns.StartDate       = Convert.ToDateTime(objJson.SelectToken("startdate"));
                objMerchantCampaigns.EndDate         = Convert.ToDateTime(objJson.SelectToken("enddate"));
                objMerchantCampaigns.StateProvinceID = Convert.ToInt32(objJson.SelectToken("stateprovinceid"));
                objMerchantCampaigns.CityID          = Convert.ToInt32(objJson.SelectToken("cityid"));
                objMerchantCampaigns.CountryID       = Convert.ToInt32(objJson.SelectToken("countryid"));
                objMerchantCampaigns.Active          = true;
                await _appDbContext.MerchantCampaigns.AddAsync(objMerchantCampaigns);

                int returnVal = await _appDbContext.SaveChangesAsync();

                if (returnVal > 0)
                {
                    return(Ok(new { Status = "OK", Detail = "Merchant Campaign Created." }));
                }
                else
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support" })));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, (new { Status = "Error", Error = "Internal Server error. Please contact customer support", SystemError = ex.Message })));
            }
        }