Beispiel #1
0
        public IActionResult Post(string values)
        {
            var partner = new Partner();

            JsonConvert.PopulateObject(values, partner);

            if (!TryValidateModel(partner))
            {
                return(BadRequest(GetFullErrorMessage(ModelState)));
            }

            // Adding partner
            _partnerRepo.Add(partner);

            // Adding services
            var partnerVM = new PartnerVM();

            JsonConvert.PopulateObject(values, partnerVM);

            _partnerRepo.AddServices(partner.Id, partnerVM.Services);

            // Adding logo
            if (!String.IsNullOrEmpty(partner.Logo))
            {
                this.CreateLogoFromTempFile(partner);
            }

            return(_uow.Commit() ? Ok() : StatusCode(StatusCodes.Status500InternalServerError));
        }
        public ActionResult Create(PartnerVM partnerVM)
        {
            //Set Access Rights
            ViewData["Access"] = "";
            if (hierarchyRepository.AdminHasDomainWriteAccess(groupName))
            {
                ViewData["Access"] = "WriteAccess";
            }

            //Check Access
            RolesRepository rolesRepository = new RolesRepository();

            if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            //Update  Model from Form
            try
            {
                TryUpdateModel <PartnerVM>(partnerVM, "PartnerVM");
            }
            catch
            {
                string n = "";
                foreach (ModelState modelState in ViewData.ModelState.Values)
                {
                    foreach (ModelError error in modelState.Errors)
                    {
                        n += error.ErrorMessage;
                    }
                }
                ViewData["Message"] = "ValidationError : " + n;
                return(View("Error"));
            }

            try
            {
                partnerRepository.Add(partnerVM);
            }
            catch (SqlException ex)
            {
                LogRepository logRepository = new LogRepository();
                logRepository.LogError(ex.Message);

                ViewData["Message"] = "There was a problem with your request, please see the log file or contact an administrator for details";
                return(View("Error"));
            }

            return(RedirectToAction("List"));
        }