Esempio n. 1
0
        /// <summary>
        /// Updates an existing template
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public IHttpActionResult Put([FromBody] SmsTemplateModel model)
        {
            Validate(model);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (string.IsNullOrWhiteSpace(model.RowVersion))
            {
                return(BadRequest("This method is not allowed to Create an entity. Please use the POST verb"));
            }

            try
            {
                _templateServices.Update(AutoMapper.Mapper.Map <EFModel.Template>(model));
                _UoW.Commit();
                return(Ok());
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Esempio n. 2
0
        public ActionResult CreateEdit(Models.SmsTemplate.SmsTemplateViewModel vm)
        {
            // Demo using FluentValidation
            if (!ModelState.IsValid)
            {
                return(View(vm));
            }
            //var regExp = "<div class=\"alert alert-dismissible alert-success\" contenteditable=\"false\" style=\"display:inline-block\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\">×</button><span>" + templateField.Name + "</span></div>";
            // strip any additional spaces that Js might add in the experssion
            vm.Text = Regex.Replace(vm.Text, "alert\\s*-\\s*dismissible", "alert-dismissible");
            vm.Text = Regex.Replace(vm.Text, "alert\\s*-\\s*success", "alert-success");
            vm.Text = Regex.Replace(vm.Text, "data\\s*-\\s*dismiss", "alert-dismiss");
            if (vm.Id != 0)
            {
                templateServices.Update(AutoMapper.Mapper.Map <EFModel.Template>(vm));
            }
            else
            {
                templateServices.CreateTemplate(AutoMapper.Mapper.Map <EFModel.Template>(vm));
            }
            UoW.Commit();

            return(RedirectToAction("Index"));
        }