コード例 #1
0
ファイル: CompanyController.cs プロジェクト: anrmk/margo
        public async Task <IActionResult> AddCompanySection(long id)
        {
            var result = await _companyBusinessManager.GetCompany(id);

            if (result == null)
            {
                return(NotFound());
            }

            var companySections = await _companyBusinessManager.GetSections(id);

            var sections = await _sectionBusinessManager.GetSections();

            var exist = sections.Where(x => !companySections.Any(y => x.Id == y.SectionId)).ToList();

            var viewDataDictionary = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary())
            {
                { "SectionList", _mapper.Map <List <SectionViewModel> >(exist) }
            };

            if (exist.Count != 0)
            {
                var model = new CompanySectionViewModel()
                {
                    CompanyId = id
                };
                string html = _viewRenderService.RenderToStringAsync("_AddSectionPartial", model, viewDataDictionary).Result;
                return(Ok(html));
            }
            else
            {
                return(Ok("Nothing to display"));
            }
        }
コード例 #2
0
ファイル: CompanyController.cs プロジェクト: anrmk/margo
        public async Task <IActionResult> CreateCompanySection([FromBody] CompanySectionViewModel model)
        {
            try {
                if (ModelState.IsValid)
                {
                    var result = await _companyBusinessManager.CreateSection(_mapper.Map <CompanySectionDto>(model));

                    return(Ok(_mapper.Map <CompanySectionViewModel>(result)));
                }
            } catch (Exception er) {
                return(BadRequest(er.Message));
            }
            return(Ok());
        }
コード例 #3
0
ファイル: CompanyController.cs プロジェクト: anrmk/margo
        public async Task <ActionResult> CreateCompanySectionField([FromBody] CompanySectionViewModel model)
        {
            try {
                if (ModelState.IsValid)
                {
                    var item = await _companyBusinessManager.CreateSection(_mapper.Map <CompanySectionDto>(model));

                    if (item == null)
                    {
                        return(BadRequest());
                    }
                    return(Ok(_mapper.Map <CompanySectionViewModel>(item)));
                }
            } catch (Exception er) {
                BadRequest(er.Message);
            }

            return(BadRequest(""));
        }