public Model.CustomerApiKeyRule GetCustomerApiKeyRuleById(int id) { CustomerApiKeyRule customerApiKeyRule = _context.CustomerApiKeyRule.SingleOrDefault(x => id.Equals(x.Id)); Model.CustomerApiKeyRule customerApiKeyRuleModel = customerApiKeyRule?.MapFull(); return(customerApiKeyRuleModel); }
public HttpResponseMessage Put(Model.CustomerApiKeyRule customerApiKeyRuleModel) { try { var id = _customerApiKeyFacade().UpdateCustomerApiKeyRule(customerApiKeyRuleModel); return(Request.CreateResponse(HttpStatusCode.OK, id)); } catch (Exception e) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message)); } }
public int AddCustomerApiKeyRule(Model.CustomerApiKeyRule customerApiKeyRuleModel) { CustomerApiKeyRule customerApiKeyRule = customerApiKeyRuleModel.MapFull(); if (string.IsNullOrEmpty(customerApiKeyRule.ApplicationName) || customerApiKeyRule.ApplicationName.Contains("*")) { throw new ArgumentException($"This apikey is public and does not allow System to be wildcard."); } _context.CustomerApiKeyRule.Add(customerApiKeyRule); _context.Save(); return(customerApiKeyRule.Id); }
public int UpdateCustomerApiKeyRule(Model.CustomerApiKeyRule customerApiKeyRuleModel) { CustomerApiKeyRule customerApiKeyRule = _context.CustomerApiKeyRule.SingleOrDefault(x => x.Id.Equals(customerApiKeyRuleModel.Id)); if (customerApiKeyRule == null) { throw new ArgumentException($"No data found with id: {customerApiKeyRule.Id}"); } customerApiKeyRuleModel.MapFull(customerApiKeyRule); if (string.IsNullOrEmpty(customerApiKeyRule.ApplicationName) || customerApiKeyRule.ApplicationName.Contains("*")) { throw new ArgumentException($"This Apikey is public and does not allow System to be wildcard."); } _context.Save(); return(customerApiKeyRule.Id); }
public static CustomerApiKeyRule MapFull(this ApiKeyModel.CustomerApiKeyRule customerApiKeyRuleModel, CustomerApiKeyRule customerApiKeyRule = null) { var tmp = customerApiKeyRule ?? new CustomerApiKeyRule(); tmp.ApiKeyId = customerApiKeyRuleModel.ApiKeyId; tmp.ApplicationName = customerApiKeyRuleModel.ApplicationName; tmp.Domain = customerApiKeyRuleModel.Domain; tmp.Ip = customerApiKeyRuleModel.Ip; tmp.Method = customerApiKeyRuleModel.Method; tmp.Mode = customerApiKeyRuleModel.Mode; tmp.Operation = customerApiKeyRuleModel.Operation; tmp.Created = customerApiKeyRuleModel.Created == DateTime.MinValue ? tmp.Created : customerApiKeyRuleModel.Created; tmp.CreatedBy = customerApiKeyRuleModel.CreatedBy ?? tmp.CreatedBy; tmp.Changed = customerApiKeyRuleModel.Changed; tmp.ChangedBy = customerApiKeyRuleModel.ChangedBy; return(tmp); }
public static ApiKeyModel.CustomerApiKeyRule MapFull(this CustomerApiKeyRule customerApiKeyRule) { var customerApiKeyRuleModel = new ApiKeyModel.CustomerApiKeyRule { Id = customerApiKeyRule.Id, ApiKeyId = customerApiKeyRule.ApiKeyId, Changed = customerApiKeyRule.Changed, ChangedBy = customerApiKeyRule.ChangedBy, Created = customerApiKeyRule.Created, CreatedBy = customerApiKeyRule.CreatedBy, Domain = customerApiKeyRule.Domain, Ip = customerApiKeyRule.Ip, Method = customerApiKeyRule.Method, Mode = customerApiKeyRule.Mode, Operation = customerApiKeyRule.Operation, ApplicationName = customerApiKeyRule.ApplicationName }; return(customerApiKeyRuleModel); }
public void GetRule() { var obj = new Model.CustomerApiKeyRule { Id = 1, ApiKeyId = 11, Changed = DateTime.Now, ChangedBy = "Jitesh" }; var mock = CreateMock(); mock.Setup(x => x.GetCustomerApiKeyRuleById(1)).Returns(obj); var controller = new CustomerApiKeyRuleController(() => mock.Object) { Request = new HttpRequestMessage(), Configuration = new HttpConfiguration() }; var ret = controller.Get(1); Assert.AreEqual(Newtonsoft.Json.JsonConvert.SerializeObject(obj), ret.Content.ReadAsStringAsync().Result); }