Esempio n. 1
0
 public LibraryObject Create(SystemUserRol systemUserRol)
 {
     try
     {
         return(doSystemUserRol.Create(systemUserRol));
     }
     catch (Exception)
     {
         throw;
     }
 }
 public HttpResponseMessage Post([FromBody] SystemUserRol systemUserRol)
 {
     try
     {
         DbLibrary        dbLibrary       = new DbLibrary();
         BO_SystemUserRol boSystemUserRol = new BO_SystemUserRol(dbLibrary);
         DataMessage      dataMessage     = new DataMessage(boSystemUserRol.Create(systemUserRol));
         return(Request.CreateResponse(HttpStatusCode.OK, dataMessage));
     }
     catch (Exception e)
     {
         ErrorMessage mensaje = new ErrorMessage("2.1", "Excepción en la creación del UserRol: " + e.GetBaseException().Message, e.ToString());
         return(Request.CreateResponse(HttpStatusCode.BadRequest, mensaje));
     }
 }
        /// <summary>
        /// Agrega un nuevo registro a la entidad de userroles
        /// </summary>
        /// <param name="SystemUserRol"></param>
        /// <returns></returns>
        public Operations Create(SystemUserRol systemUserRol)
        {
            try
            {
                Operations operations = new Operations();

                try
                {
                    dbLibrary.tc_SystemUserRol.Add(systemUserRol);
                    dbLibrary.SaveChanges();
                    operations.Result  = "OK";
                    operations.Message = "Registro creado";
                }
                catch (DbEntityValidationException e)
                {
                    regOperacion = new StringBuilder("No se logro crear el registro:-");
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        regOperacion.AppendFormat("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                                  eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            regOperacion.AppendFormat("- Property: \"{0}\", Error: \"{1}\"",
                                                      ve.PropertyName, ve.ErrorMessage);
                        }
                    }

                    operations.Result  = "Error";
                    operations.Message = regOperacion.ToString();
                }

                return(operations);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }