Пример #1
0
        /// <summary>
        /// Update Role by Id.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="role"></param>
        /// <returns></returns>
        /// <response code="200">Returns the newly-created item</response>
        /// <response code="400">If the item is null</response>

        public IHttpActionResult Put([FromBody] Role role, string id)
        {
            try
            {
                List <string> errors = ValidateExtensions.ValidateRole(role);

                if (errors.Count > 0)
                {
                    return(Content(HttpStatusCode.BadRequest, errors));
                }
                if (TimeUnit.Roles.Get(id) == null)
                {
                    return(NotFound());
                }
                TimeUnit.Roles.Update(role, id);
                TimeUnit.Save();
                Utility.Log($"ROLE CONTROLLER: Put Called on Role, Successfully updated id: {id}.", "INFO");
                return(Ok(TimeFactory.Create(role)));
            }
            catch (Exception ex)
            {
                Utility.Log($"ROLE CONTROLLER: Put Cannot be called on Role.", "ERROR", ex);
                return(BadRequest(ex.Message));
            }
        }
Пример #2
0
        /// <summary>
        /// Insert Role.
        /// </summary>
        /// <param name="role"></param>
        /// <returns></returns>
        /// <response code="200">Returns the newly-created item</response>
        /// <response code="400">If the item is null</response>

        public IHttpActionResult Post([FromBody] Role role)
        {
            try
            {
                List <string> errors = ValidateExtensions.ValidateRole(role);

                if (errors.Count > 0)
                {
                    return(Content(HttpStatusCode.BadRequest, errors));
                }

                TimeUnit.Roles.Insert(role);
                TimeUnit.Save();
                Utility.Log($"ROLE CONTROLLER: Post Called on Role, Successfully added: {role.Name}.", "INFO");
                return(Ok(TimeFactory.Create(role)));
            }
            catch (Exception ex)
            {
                Utility.Log($"ROLE CONTROLLER: Post Cannot be called on Role.", "ERROR", ex);
                return(BadRequest(ex.Message));
            }
        }