//[ValidateAntiForgeryToken]
        public async Task <JsonResult> Edit([Bind(Include = "Id,DistributorId,CampaignTitle,SocialMediaId,IndustryId,City,Gender,Message,CampaignType, LaunchDate")] CampaignViewModel campaignViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { success = false, Response = "", Error = ErrorHelper.GetModelStateErrorMessages(ModelState) }, JsonRequestBehavior.AllowGet));
            }

            var errorMessage = "";
            var distributor  = new Distributor();

            if (!IdentityHelper.TryGetDistributor(User, out distributor, out errorMessage))
            {
                return(Json(new { success = false, Response = "", Error = errorMessage }, JsonRequestBehavior.AllowGet));
            }

            try
            {
                _campaignAdapter.Update(campaignViewModel, distributor);

                return(Json(new { success = true, Response = campaignViewModel, Error = "" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception exception)
            {
                return(Json(new { success = false, Response = "", Error = exception.Message }, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #2
0
        public JsonResult Edit(CampaignViewModel campaignViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(new JsonResult(new { success = false, Response = "", Error = ErrorHelper.GetModelStateErrorMessages(ModelState) }));
            }

            if (!_identityHelper.TryGetDistributor(out Distributor distributor, out string errorMessage))
            {
                return(new JsonResult(new { success = false, Response = "", Error = errorMessage }));
            }

            try
            {
                _campaignAdapter.Update(campaignViewModel, distributor);

                return(new JsonResult(new { success = true, Response = campaignViewModel, Error = "" }));
            }
            catch (Exception exception)
            {
                return(new JsonResult(new { success = false, Response = "", Error = exception.Message }));
            }
        }