Exemple #1
0
        public object AddRole([FromBody] string value)
        {
            APP_ROLE roleToAdd = null;

            try
            {
                roleToAdd = JsonConvert.DeserializeObject <APP_ROLE>(value);

                var executingUser = "";
                var str           = string.Format("User {0} created a new role with the following data: \n\n{1}", executingUser, value);

                APP_ROLE result = _service.AddRole(roleToAdd);
                log.Info(str);
                return(Ok(result));
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    StringBuilder errmsg = new StringBuilder();

                    errmsg.Append(string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                                eve.Entry.Entity.GetType().Name, eve.Entry.State.ToString()));
                    foreach (var ve in eve.ValidationErrors)
                    {
                        errmsg.Append(string.Format("- Property: \"{0}\", Error: \"{1}\"",
                                                    ve.PropertyName, ve.ErrorMessage));
                    }
                    log.Error(e);
                }
                return(BadRequest("netApi.Controller.AddUser(string) caused DbEntityValidationException!"));
            }
            catch (Exception e)
            {
                log.Error(e);

                return(BadRequest(e.Message));
            }
        }
 public APP_ROLE AddRole(APP_ROLE roleToAdd)
 {
     return(_repository.AddRole(roleToAdd));
 }