Ejemplo n.º 1
0
        public async Task <ActionResult <JObject> > SaveData(string name, string formName, [FromBody] JObject obj)
        {
            // Get module by name
            string _username = User?.Claims.FirstOrDefault(c => c.Type == "Username")?.Value;
            var    result    = await ODataMobileViewModel.SaveByModuleName(_lang, _username, name, formName, obj);

            if (result.IsSucceed)
            {
                return(Ok(result));
            }
            else
            {
                return(BadRequest(result));
            }
        }
        public async Task <ActionResult <ODataMobileViewModel> > SaveByName(string culture, string name, [FromBody] JObject obj)
        {
            var getAttrSet = await Mix.Cms.Lib.ViewModels.MixAttributeSets.ReadViewModel.Repository.GetSingleModelAsync(m => m.Name == name);

            string _username = User?.Claims.FirstOrDefault(c => c.Type == "Username")?.Value;

            if (getAttrSet.IsSucceed)
            {
                ODataMobileViewModel data = new ODataMobileViewModel()
                {
                    Id               = obj["id"]?.Value <string>(),
                    CreatedBy        = _username,
                    AttributeSetId   = getAttrSet.Data.Id,
                    AttributeSetName = getAttrSet.Data.Name,
                    Specificulture   = culture,
                    Data             = obj
                };
                var portalResult = await base.SaveAsync <ODataMobileViewModel>(data, true);

                if (portalResult.IsSucceed)
                {
                    if (getAttrSet.Data.EdmAutoSend.HasValue && getAttrSet.Data.EdmAutoSend.Value)
                    {
                        _ = MixService.SendEdm(_lang, getAttrSet.Data.EdmTemplate, portalResult.Data.Data, getAttrSet.Data.EdmSubject, getAttrSet.Data.EdmFrom);
                    }

                    return(Ok(new RepositoryResponse <JObject>
                    {
                        IsSucceed = true,
                        Data = portalResult.Data.Data
                    }));
                }
                else
                {
                    return(BadRequest(portalResult));
                }
            }
            else
            {
                return(NotFound());
            }
        }