public IHttpActionResult Post(MappingModel model)
 {
     try
     {
         if (string.IsNullOrWhiteSpace(model.MappingId))
         {
             _mappingManager.CreateMapping(model);
         }
         else
         {
             _mappingManager.UpdateMapping(model);
         }
         return(Ok());
     }
     catch (WebException exception)
     {
         LogHelper.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exception.Message, exception);
         return(BadRequest(exception.Message + " Please check your credentials"));
     }
     catch (Exception exception)
     {
         LogHelper.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exception.Message, exception);
         return(BadRequest(exception.Message));
     }
 }
Beispiel #2
0
 public void Post(MappingModel model)
 {
     try
     {
         if (string.IsNullOrWhiteSpace(model.MappingId))
         {
             _mappingManager.CreateMapping(model);
         }
         else
         {
             _mappingManager.UpdateMapping(model);
         }
     }
     catch (WebException exception)
     {
         LogHelper.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exception.Message, exception);
         throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest,
                                                                     exception.Message + " Please check your credentials"));
     }
     catch (Exception exception)
     {
         LogHelper.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exception.Message, exception);
         throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, exception.Message));
     }
 }
        public ActionResult Post(PostMappingViewModel model)
        {
            if (model.TemplateId == null)
            {
                return(Json(new { status = "error", message = "GatherContent template isn't selected" }, JsonRequestBehavior.AllowGet));
            }
            try
            {
                var postMappingModel = new MappingModel
                {
                    DefaultLocationId = model.DefaultLocation,
                    MappingTitle      = model.GcMappingTitle,
                    MappingId         = model.ScMappingId,
                    GcTemplate        = new GcTemplateModel {
                        Id = model.TemplateId
                    },
                    CmsTemplate = new CmsTemplateModel {
                        Id = model.SelectedTemplateId
                    },
                    FieldMappings = GetFieldMappings(model.TemplateTabs)
                };
                if (model.IsEdit)
                {
                    MappingManager.UpdateMapping(postMappingModel);
                }
                else
                {
                    MappingManager.CreateMapping(postMappingModel);
                }

                return(new EmptyResult());
            }
            catch (WebException exception)
            {
                Log.Error("GatherContent message: " + exception.Message + exception.StackTrace, exception);
                return(Json(new { status = "error", message = exception.Message + " Please check your credentials" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                Log.Error("GatherContent message: " + e.Message + e.StackTrace, e);

                return(Json(new { status = "error", message = e.Message }, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #4
0
        public void Post(PostMappingViewModel model)
        {
            object resultObject = null;

            try
            {
                if (model.TemplateId == null)
                {
                    resultObject = new { status = "error", message = "GatherContent template isn't selected" };
                    //return Json(new { status = "error", message = "GatherContent template isn't selected" }, JsonRequestBehavior.AllowGet);
                }
                else
                {
                    var postMappingModel = new MappingModel
                    {
                        DefaultLocationId = model.DefaultLocation,
                        MappingTitle      = model.GcMappingTitle,
                        MappingId         = model.ScMappingId,
                        GcTemplate        = new GcTemplateModel {
                            Id = model.TemplateId
                        },
                        CmsTemplate = new CmsTemplateModel {
                            Id = model.SelectedTemplateId
                        },
                        FieldMappings = GetFieldMappings(model.TemplateTabs)
                    };
                    if (model.IsEdit)
                    {
                        MappingManager.UpdateMapping(postMappingModel);
                    }
                    else
                    {
                        MappingManager.CreateMapping(postMappingModel);
                    }

                    //return new EmptyResult();
                }
            }
            catch (WebException exception)
            {
                Log.Error("GatherContent message: " + exception.Message + exception.StackTrace, exception);
                resultObject = new { status = "error", message = exception.Message + " Please check your credentials" };
                //return Json(new { status = "error", message = exception.Message + " Please check your credentials" }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception e)
            {
                Log.Error("GatherContent message: " + e.Message + e.StackTrace, e);
                resultObject = new { status = "error", message = e.Message };
                //return Json(new { status = "error", message = e.Message }, JsonRequestBehavior.AllowGet);
            }
            finally
            {
                Context.Response.Clear();
                Context.Response.ContentType = "application/json";
                JavaScriptSerializer js = new JavaScriptSerializer();
                if (resultObject != null)
                {
                    Context.Response.Write(js.Serialize(resultObject));
                }
                else
                {
                    Context.Response.Write(String.Empty);
                }
            }
        }