public IActionResult FindAll([FromHeader(Name = "Accept")] string mediaType) { var users = _repository.FindAllAsync().ToList(); if (mediaType == CustomMediaType.Hateoas) { var dtousers = _mapper.Map <List <ApplicationUser>, List <DTOUser> >(users); foreach (var user in dtousers) { user.Links.Add(new DTOLink("self", Url.Link("FindUser", new { id = user.Id }), "GET")); } var list = new DTOList <DTOUser> { Results = dtousers }; list.Links.Add(new DTOLink("self", Url.Link("FindAll", null), "GET")); return(Ok(list)); } else { return(Ok(users)); } }
public async Task <ActionResult> SubmitRequestList(DTOList <ItemDTO> items) { string identityUserId = User.Identity.GetUserId(); int userId = Convert.ToInt32(identityUserId); items.ForEach(n => { n.AssociatedUserId = userId; }); ResultDTO result = null; try { result = await DataService.CallDataService <ResultDTO>("Item", "RequestItems", items); if (result.StatusCodeSuccess) { result.StatusMessage = "Your requests have been submitted to the admin. Thank you!"; } } catch (Exception ex) { DataService.SendEmail(ex.Message, ex.InnerException.ToString(), isError: true); } return(new JsonResult { Data = result }); }
public IActionResult FindAllMessages(string userOneId, string userTwoId, [FromHeader(Name = "Accept")] string mediaType) { if (userOneId == userTwoId) { return(UnprocessableEntity()); } var messages = _repo.FindAll(userOneId, userTwoId).ToList(); if (mediaType == CustomMediaType.Hateoas) { var dtomessages = _mapper.Map <List <Message>, List <DTOMessage> >(messages); var list = new DTOList <DTOMessage> { Results = dtomessages }; list.Links.Add(new DTOLink("self", Url.Link("FindAllMessages", null), "GET")); return(Ok(list)); } else { return(Ok(messages)); } }
public async Task <DTOList <T> > CallDataServiceList <T>(string controller, string action, object postData = null) where T : DTOBase, new() { PropertyInfo[] properties = typeof(T).GetProperties(); DTOList <T> retList = default(DTOList <T>); string path = String.Format(DS_PATH, controller, action); HttpResponseMessage response; if (postData == null) { response = await Client.GetAsync(path); } else { if (!(postData is DTOBase) && !(postData is IDtoList)) { throw new Exception("Have to pass in a DTOList<T> or DTOBase for the postData parameter"); } response = await Client.PostAsJsonAsync(path, postData); } if (response.IsSuccessStatusCode) { retList = await response.Content.ReadAsAsync <DTOList <T> >(); retList.StatusCode = (int)response.StatusCode; retList.StatusCodeSuccess = true; foreach (var obj in retList) { obj.StatusCode = (int)response.StatusCode; obj.StatusCodeSuccess = true; List <PropertyInfo> dates = (from n in properties where n.PropertyType == typeof(DateTime) || n.PropertyType == typeof(DateTime?) select n).ToList(); dates.ForEach(n => { typeof(T).GetProperty(n.Name + "JS").SetValue(obj, (n.GetValue(obj) == null ? "" : n.GetValue(obj).ToString())); }); } } else { retList = new DTOList <T>(); retList.StatusCode = (int)response.StatusCode; retList.StatusCodeSuccess = false; } Debug.WriteLine(JsonConvert.SerializeObject(postData)); Debug.WriteLine(JsonConvert.SerializeObject(retList)); return(retList); }
public DTOList <SubLocationDTO> GetSubLocations() { DTOList <SubLocationDTO> retValue = null; using (var context = new DataAccessContext()) { var subLocations = (from n in context.SubLocations select n).ToList(); retValue = retValue.DTOConvert(subLocations); } return(retValue); }
public DTOList <AgeGroupDTO> GetAgeGroups() { DTOList <AgeGroupDTO> retValue = null; using (var context = new DataAccessContext()) { var ageGroups = (from n in context.AgeGroups select n).ToList(); retValue = retValue.DTOConvert(ageGroups); } return(retValue); }
public DTOList <CategoryDTO> GetCategories() { DTOList <CategoryDTO> retValue = null; using (var context = new DataAccessContext()) { var categories = (from n in context.Categories select n).ToList(); retValue = retValue.DTOConvert(categories); } return(retValue); }
public DTOList <ItemDTO> GetItemCheckouts() { DTOList <ItemDTO> retValue = null; using (var context = new DataAccessContext()) { var list = (from n in context.Items where n.CheckOutDate != null select n).ToList(); retValue = retValue.DTOConvert(list); } return(retValue); }
public DTOList <UserDTO> GetUsers() { DTOList <UserDTO> retValue = null; using (var context = new DataAccessContext()) { var list = (from n in context.Users select n).ToList(); retValue = retValue.DTOConvert(list); } return(retValue); }
public DTOList <ItemDTO> GetItems() { DTOList <ItemDTO> retValue = null; using (var context = new DataAccessContext()) { var items = (from i in context.Items select i).ToList(); retValue = retValue.DTOConvert(items); retValue.StatusMessage = $"Found {items.Count} items"; } return(retValue); }
public static DTOList <T> DTOConvertNonRecursive <T>(this DTOList <T> list, object convertFrom) where T : DTOBase, new() { if (list == null) { list = new DTOList <T>(); } foreach (var fromObj in ((IList)convertFrom)) { T toObj = new T(); toObj = toObj.DTOConvertNonRecursive <T>(fromObj); list.Add(toObj); } return(list); }
public ResultDTO RequestItems(DTOList <ItemDTO> dtoItems) { ResultDTO result = null; try { using (var context = new DataAccessContext()) { var idList = dtoItems.Select(n => n.ID); var items = (from n in context.Items where idList.Contains(n.ID) select n).ToList(); items.ForEach(item => { item.AssociatedUserId = dtoItems.Where(dto => dto.ID == item.ID).First().AssociatedUserId; item.RequestDate = DateTime.Now; }); context.SaveChanges(); result = new ResultDTO { StatusCode = (int)HttpStatusCode.OK, StatusCodeSuccess = true, StatusMessage = $"Updated {items.Count} items" }; } } catch (Exception ex) { result = new ResultDTO { StatusCode = (int)HttpStatusCode.InternalServerError, StatusCodeSuccess = false, StatusMessage = ex.ToString() }; } return(result); }
public DTOList <ItemDTO> GetItems(ItemFilterDTO filter) { DTOList <ItemDTO> retValue = null; using (var context = new DataAccessContext()) { var items = (from n in context.Items where n.CategoryId == filter.CategoryId && n.AssociatedUserId == null // no one has it checked out or requested select n).ToList(); if (filter.AgeGroupId > 0) { items = (from i in items where i.Item2AgeGroup.Count(n => n.AgeGroupId == filter.AgeGroupId) > 0 select i).ToList(); } if (filter.SubjectId > 0) { items = (from i in items where i.Item2Subject.Count(n => n.SubjectId == filter.SubjectId) > 0 select i).ToList(); } if (filter.LocationId > 0) { items = (from i in items where i.LocationId == filter.LocationId select i).ToList(); } retValue = retValue.DTOConvert(items); retValue.StatusMessage = $"Found {items.Count} items"; } return(retValue); }
public ListView(DTOList <T> dto, ICallContext context, string name, IEnumerable <object> items) { this.Add("header", new ViewListHeader(dto.Total, dto.Page, dto.PageSize, context.LocalPath)); this.Add(name, items.ToList()); }
public static DTOList <T> DTOConvert <T>(this DTOList <T> list, object convertFromList) where T : DTOBase { IMapper mapper = Mapper.Configuration.CreateMapper(); return(mapper.Map <DTOList <T> >(convertFromList)); }