Exemplo n.º 1
0
        public IActionResult Update(int id, [FromBody] TimeZoneUpdateModel model)
        {
            // map model to entity and set id
            var timeZone = _mapper.Map <Entities.TimeZone>(model);

            timeZone.Id = id;

            var currUser = _userService.GetById(Int32.Parse(User.Identity.Name));

            if (timeZone.UserId == currUser.Id || _userService.CheckIf(currUser, Roles.ROLE_ADMIN))
            {
                try
                {
                    _timeZoneService.Update(timeZone);
                    return(Ok());
                }
                catch (AppException ex)
                {
                    // return error message if there was an exception
                    return(BadRequest(new { message = ex.Message }));
                }
            }
            else
            {
                return(StatusCode(403, "Unauthorized! Only 'Admin' or the owner can update this resource"));
            }
        }
Exemplo n.º 2
0
    public bool UpdateEntity()
    {
        ITimeZoneService service        = null;
        bool             validateupdate = false;

        try
        {
            // Validate the entity values.
            if (hdnTimeZoneId.Value != "0")
            {
                this.ValidateEntity("Update");
            }
            else
            {
                this.ValidateEntity(string.Empty);
            }

            // Build entity.
            Tks.Entities.TimeZone entity = new Tks.Entities.TimeZone();
            entity.Id          = Int32.Parse(this.hdnTimeZoneId.Value);
            entity.Name        = this.txtName.Value;
            entity.ShortName   = this.txtShortName.Value;
            entity.Description = this.txtDescription.InnerText.ToString().Replace("<", "");
            if (hdnTimeZoneId.Value != "0")
            {
                entity.IsActive = this.chkIsActive.Checked;
            }
            else
            {
                entity.IsActive = true;
            }
            entity.Reason           = this.txtReason.Value;
            entity.LastUpdateUserId = 1;
            entity.LastUpdateDate   = DateTime.Now;
            // Create service and call method.
            service            = AppService.Create <ITimeZoneService>();
            service.AppManager = mAppManager;
            service.Update(entity);

            // Display succeed message.
        }

        catch (ValidationException ve)
        {
            // Display validation erros.
            this.DisplayValidationMessage(ve);
            validateupdate = true;
        }
        catch (Exception ex)
        {
            validateupdate = true;
            throw ex;
        }
        finally
        {
            if (service != null)
            {
                service.Dispose();
            }
        }
        return(validateupdate);
    }