Example #1
0
        public DtoActionResult Update(EntityWolRelay relay)
        {
            var u = GetWolRelay(relay.Id);

            if (u == null)
            {
                return new DtoActionResult {
                           ErrorMessage = "Wol Relay Not Found", Id = 0
                }
            }
            ;

            var actionResult = new DtoActionResult();

            var validationResult = Validate(relay, false);

            if (validationResult.Success)
            {
                _uow.WolRelayRepository.Update(relay, u.Id);

                _uow.Save();
                actionResult.Success = true;
                actionResult.Id      = relay.Id;
            }
            else
            {
                return(new DtoActionResult()
                {
                    ErrorMessage = validationResult.ErrorMessage
                });
            }
            return(actionResult);
        }
Example #2
0
        public DtoActionResult Put(int id, EntityWolRelay relay)
        {
            relay.Id = id;
            var result = _wolRelayService.Update(relay);

            if (result == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }
            return(result);
        }
Example #3
0
        public DtoValidationResult Validate(EntityWolRelay relay, bool isNew)
        {
            IPAddress gateway;

            if (!IPAddress.TryParse(relay.Gateway, out gateway))
            {
                return new DtoValidationResult()
                       {
                           ErrorMessage = "Invalid Gateway Address", Success = false
                       }
            }
            ;


            var validationResult = new DtoValidationResult();

            if (isNew)
            {
                if (_uow.WolRelayRepository.Exists(h => h.Gateway == relay.Gateway))
                {
                    validationResult.Success      = false;
                    validationResult.ErrorMessage = "A Relay With This Gateway Already Exists";
                    return(validationResult);
                }
            }
            else
            {
                var originalRelay = _uow.WolRelayRepository.GetById(relay.Id);

                if (originalRelay.Gateway != relay.Gateway)
                {
                    if (_uow.WolRelayRepository.Exists(h => h.Gateway == relay.Gateway))
                    {
                        validationResult.Success      = false;
                        validationResult.ErrorMessage = "A Relay With This Gateway Already Exists";
                        return(validationResult);
                    }
                }
            }

            return(new DtoValidationResult()
            {
                Success = true
            });
        }
    }
Example #4
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            RequiresAuthorization(AuthorizationStrings.Administrator);
            ImpersonationAccount = !string.IsNullOrEmpty(Request["impersonationId"])
                ? Call.ImpersonationAccountApi.Get(Convert.ToInt32(Request.QueryString["impersonationId"]))
                : null;

            ComServer = !string.IsNullOrEmpty(Request["serverId"])
                ? Call.ClientComServerApi.Get(Convert.ToInt32(Request.QueryString["serverId"]))
                : null;

            ComServerCluster = !string.IsNullOrEmpty(Request["clusterId"])
                ? Call.ComServerClusterApi.Get(Convert.ToInt32(Request.QueryString["clusterId"]))
                : null;

            WolRelay = !string.IsNullOrEmpty(Request["relayId"])
                ? Call.WolRelayApi.Get(Convert.ToInt32(Request.QueryString["relayId"]))
                : null;
        }
Example #5
0
        protected void buttonAddRelay_OnClick(object sender, EventArgs e)
        {
            var wolRelay = new EntityWolRelay()
            {
                Gateway     = txtGateway.Text,
                ComServerId = Convert.ToInt32(ddlComServer.SelectedValue)
            };

            var result = Call.WolRelayApi.Post(wolRelay);

            if (result.Success)
            {
                EndUserMessage = "Successfully Created WOL Relay";
                Response.Redirect("~/views/admin/wolrelays/edit.aspx?level=2&relayId=" + result.Id);
            }
            else
            {
                EndUserMessage = result.ErrorMessage;
            }
        }
Example #6
0
        public DtoActionResult Add(EntityWolRelay relay)
        {
            var actionResult = new DtoActionResult();

            var validationResult = Validate(relay, true);

            if (validationResult.Success)
            {
                _uow.WolRelayRepository.Insert(relay);
                _uow.Save();
                actionResult.Success = true;
                actionResult.Id      = relay.Id;
            }
            else
            {
                return(new DtoActionResult()
                {
                    ErrorMessage = validationResult.ErrorMessage
                });
            }

            return(actionResult);
        }
Example #7
0
 public DtoActionResult Post(EntityWolRelay relay)
 {
     return(_wolRelayService.Add(relay));
 }