public async Task <IActionResult> AddProduct([FromRoute] int id, [FromRoute] int idp) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var collection = await collectionRepository.AddCollectionProduct(id, idp); if (collection == null) { return(BadRequest()); } CollectionDTO dto = new CollectionDTO(); dto.CollectionId = collection.CollectionId; dto.collectionName = collection.collectionName; dto.aestheticParameter = collection.aestheticParameter; dto.products = new List <ProductDTO>(); foreach (CollectionProduct cp in collection.CollectionProducts) { ProductDTO pdto = productToDTO(cp.Product); dto.products.Add(pdto); } return(Ok(dto)); }
public async Task <IActionResult> PutCollection([FromRoute] int id, [FromBody] CollectionDTO collectionDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != collectionDTO.CollectionId) { return(BadRequest()); } var collection = await collectionRepository.Edit(id, collectionDTO); if (collection == null) { return(BadRequest()); } CollectionDTO cdto = new CollectionDTO(); cdto.CollectionId = collection.CollectionId; cdto.collectionName = collection.collectionName; cdto.aestheticParameter = collection.aestheticParameter; cdto.products = new List <ProductDTO>(); foreach (CollectionProduct cp in collection.CollectionProducts) { ProductDTO productDTO = productToDTO(cp.Product); cdto.products.Add(productDTO); } return(Ok(cdto)); }
//inserting pos collection public CollectionDTO InsertPosCollection(CollectionDTO CollectionRequest) { Decimal collectionAmount = 0; var UserVerify = _db.aspnetusers.Where(o => o.Id == CollectionRequest.USER_ID).SingleOrDefault(); var PosVerify = _db.pos.Where(o => o.POS_ID == CollectionRequest.POS_ID).SingleOrDefault(); if (UserVerify == null || PosVerify == null) { return(null); } var Remittance = _db.remittances.Where(o => o.USER_ID == CollectionRequest.USER_ID).SingleOrDefault(); if (Remittance != null && Remittance.remittance_status == RemittanceStatus.NonRemite) { CollectionRequest.Message = 2; return(CollectionRequest); } var collection = _db.pos_collections.Where(o => o.USER_ID == CollectionRequest.USER_ID && o.CollectionStatus == 0 && o.MDAStation_ID == CollectionRequest.MDAStation_ID) .FirstOrDefault(); if (collection != null) { collectionAmount = _db.pos_collections.Where(o => o.USER_ID == CollectionRequest.USER_ID && o.CollectionStatus == 0 && o.MDAStation_ID == CollectionRequest.MDAStation_ID) .Select(o => o.Amount).Sum(); } var TotalAmount = collectionAmount + CollectionRequest.Amount; if (TotalAmount >= UserVerify.UserLimit) { CollectionRequest.Message = 1; return(CollectionRequest); } CollectionRequest.COLLECTION_ID = "CO" + RandomNumber(); pos_collection CollectionMap = Mapper.Map <CollectionDTO, pos_collection>(CollectionRequest); CollectionMap.create_at = GetCurrentDateTime(); if (CollectionRequest.Type) { CollectionMap.CollectionType = CollectionType.Tax; } var CollectionResponse = _db.pos_collections.Add(CollectionMap); _db.SaveChanges(); CollectionDTO CollectionResponseDTO = Mapper.Map <pos_collection, CollectionDTO>(CollectionResponse); return(CollectionResponseDTO); }
public async Task TestPutCollectionFail() { CollectionDTO dto = new CollectionDTO(); dto.CollectionId = 1000; dto.collectionName = "Test_Collection_Updated"; dto.aestheticParameter = "Second_Mock_Parameter_Updated"; dto.products = new List <ProductDTO>(); //Should not update if the collection does not exist var result = await controller.PutCollection(1000, dto); Assert.IsType <BadRequestResult>(result); //Should not update if there is a mismatch between a route id and CollectionId dto.CollectionId = 1; var result1 = await controller.PutCollection(1000, dto); Assert.IsType <BadRequestResult>(result1); //Should not update if there is a collection with the updated name already dto.collectionName = "Second_Test_Collection"; var result2 = await controller.PutCollection(1, dto); Assert.IsType <BadRequestResult>(result2); }
public async Task <List <Item> > GenerateItem(CollectionDTO collection) { RestService service = new RestService(); List <ItemDTO> DTOitems = await service.GetItemsFromDB(collection); List <ImageDTO> imageURLS = await service.GetAllImages(collection); List <Item> items = new List <Item>(); foreach (var item in DTOitems) { foreach (var image in imageURLS) { if (item.Id == image.ItemId) { Item it = new Item(); it.Id = item.Id; it.ItemName = item.ItemName; it.Description = item.Description; it.AuctionURL = item.AuctionURL; it.ForSale = item.ForSale; it.ImageURL = image.ImageURL; items.Add(it); } } } return(items); }
public CollectionDTO GetCollection(int collectionID) { CollectionDTO item = null; using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.DatabaseConnectoin)) { connection.Open(); using (SqlCommand command = new SqlCommand()) { command.CommandText = "SELECT [CollectionID], [Name], [Description], [DisplayOrder] FROM [dbo].[Collection] WITH (NOLOCK) WHERE [CollectionID] = @CollectionID"; command.CommandType = CommandType.Text; command.Parameters.AddWithValue("@CollectionID", collectionID); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { item = Populate(reader); } } } connection.Close(); connection.Dispose(); } return(item); }
public EditItemPage(Item currentItem, CollectionDTO currentCollection, AccountDetails signedInUser) { SignedInUser = signedInUser; CurrentItem = currentItem; CurrentCollection = currentCollection; InitializeComponent(); }
public Task <HttpResponseMessage> PostNewColldectionToDB(CollectionDTO collection) { string json = JsonConvert.SerializeObject(collection, Formatting.Indented); HttpContent content = new StringContent(json, Encoding.UTF8, "application/json"); return(_client.PostAsync(localUri + "UserCollections", content)); }
public Collection LoadCollection(int collectionID, bool includeItems) { CollectionDTO collectionDTO = _collectionRepo.GetCollection(collectionID); if (collectionDTO == null) { return(null); } Collection obj = new Collection(); obj.CollectionID = collectionDTO.CollectionID; obj.Name = collectionDTO.Name; obj.LongDescription = collectionDTO.Description; obj.Images = _imageLoader.LoadImages(collectionDTO.CollectionID.Value); obj.Attributes = _attributeLoader.LoadAttributes(collectionDTO.CollectionID.Value); if (includeItems) { obj.Items = _itemLoader.LoadItems(collectionDTO.CollectionID.Value, true); } List <CollectionRelationshipDTO> children = _collectionRelationshipRepo.GetCollectionRelationships(obj.CollectionID.Value); obj.Collections = children.Select(x => LoadCollection(x.CollectionID, includeItems)).ToList(); return(obj); }
public async Task <IActionResult> PostCollection([FromBody] CollectionDTO collectionDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var collection = await collectionRepository.Add(collectionDTO); if (collection == null) { return(BadRequest()); } CollectionDTO colDTO = new CollectionDTO(); colDTO.CollectionId = collection.CollectionId; colDTO.collectionName = collection.collectionName; colDTO.aestheticParameter = collection.aestheticParameter; colDTO.products = new List <ProductDTO>(); foreach (CollectionProduct cp in collection.CollectionProducts) { ProductDTO productDTO = productToDTO(cp.Product); colDTO.products.Add(productDTO); } return(CreatedAtAction("PostCollection", colDTO)); }
public IHttpActionResult PosCollection(CollectionDTO CollectionRequest) { if (!ModelState.IsValid) { return(GetErrorMsg(1, "Parameter Missing")); } CollectionDTO CollectionResponse = utility.InsertPosCollection(CollectionRequest); if (CollectionResponse == null) { return(GetErrorMsg(2, "Unable to insert record")); } if (CollectionResponse.Message == 1) { return(GetErrorMsg(2, "Collection Limit Exceeded")); } if (CollectionResponse.Message == 2) { return(GetErrorMsg(2, "Pinding Remittance")); } return(Ok(CollectionResponse)); }
public ItemPage(CollectionDTO collection, AccountDetails signedInUser) { service = new RestService(); SignedInUser = signedInUser; CurrentCollection = collection; InitializeComponent(); GetItemsDB(collection); }
public CreateItemPage(AccountDetails signedInUser, CollectionDTO currentCollection) { service = new RestService(); SignedInUser = signedInUser; CurrentCollection = currentCollection; SignedInUser = signedInUser; InitializeComponent(); }
async void ClickedOnCollection(object sender, EventArgs e) { var myListView = (ListView)sender; CollectionDTO collection = (CollectionDTO)myListView.SelectedItem; await Navigation.PushAsync(new ItemPage(collection, SignedInUser)); }
async void GetItemsDB(CollectionDTO collection) { Title = collection.CollectionName; DataHandler data = new DataHandler(); List <Item> items = await data.GenerateItem(collection); ItemListview.ItemsSource = items; BindingContext = items; }
private static CollectionDTO Populate(SqlDataReader reader) { CollectionDTO obj = new CollectionDTO() { DisplayOrder = reader.GetInt32(reader.GetOrdinal("DisplayOrder")), Name = reader.GetString(reader.GetOrdinal("Name")), CollectionID = reader.GetInt32(reader.GetOrdinal("CollectionID")), Description = reader.GetString(reader.GetOrdinal("Description")) }; return(obj); }
public ItemContentPage(Item currentItem, CollectionDTO currentCollection, AccountDetails signedInUser) { service = new RestService(); images = new List <string>(); imageIndex = 0; SignedInUser = signedInUser; CurrentCollection = currentCollection; CurrentItem = currentItem; InitializeComponent(); ItemName.Text = currentItem.ItemName; ItemDesc.Text = currentItem.Description; GetImagesFromDB(currentItem); }
public async Task TestPostCollectionFail() { CollectionDTO dto = new CollectionDTO(); dto.collectionName = "Test_Collection"; dto.aestheticParameter = "Post_Mock_Parameter"; dto.products = new List <ProductDTO>(); //Should not create the new collection if the name already exists var result = await controller.PostCollection(dto); Assert.IsType <BadRequestResult>(result); }
async void AddCollection_Clicked(object sender, EventArgs e) { RestService service = new RestService(); CollectionDTO newCollection = new CollectionDTO(); newCollection.CollectionName = newCollectionName.Text; newCollection.IsShared = false; newCollection.UserProfileId = Convert.ToInt32(SignedInUser.Id); if (newCollection != null || newCollection.CollectionName != "") { service.PostNewColldectionToDB(newCollection).Wait(); var vUpdatedPage = new CollectionPage(SignedInUser); Navigation.InsertPageBefore(vUpdatedPage, this); await Navigation.PopAsync(); } }
public async Task <List <ItemDTO> > GetItemsFromDB(CollectionDTO collection) { List <ItemDTO> items = new List <ItemDTO>(); try { HttpResponseMessage response = await _client.GetAsync(localUri + "Item/collection/" + collection.Id); if (response.IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); items = JsonConvert.DeserializeObject <List <ItemDTO> >(content); } } catch (Exception ex) { Debug.WriteLine("\tERROR {Can't get items from backend}", ex.Message); } return(items); }
public async Task <IHttpActionResult> GetCollection(int id) { Collection c = await db.Collections.FindAsync(id); if (c == null) { return(NotFound()); } CollectionDTO collection = new CollectionDTO { Id = c.Id, Name = c.Name, Desc = c.Desc }; return(Ok(collection)); }
public async Task TestDeleteProductSuccess() { //Should update Collection by deleting a product from its list var result = await controller.AddProduct(1, 1); result = await controller.DeleteProduct(1, 1); Assert.IsType <OkObjectResult>(result); OkObjectResult new_res = (OkObjectResult)await controller.GetCollection(1); CollectionDTO new_dto = (CollectionDTO)new_res.Value; //Information inside the retrived CollectionDTO should be updated Assert.Equal("Test_Collection", new_dto.collectionName); Assert.Equal("Mock_Parameter", new_dto.aestheticParameter); Assert.True(1 == new_dto.CollectionId); Assert.True(0 == new_dto.products.Count); }
public static CollectionDTO AsItemCollectionDTO(this ExampleCollection collection, bool includeItems) { var itemDTOs = new List <ItemDTO>(); if (includeItems && collection.ExampleItems != null) { itemDTOs = collection.ExampleItems.Select(i => i.AsItemDTO()).ToList(); } var collectionDTO = new CollectionDTO { ExampleCollectionId = collection.ExampleCollectionId, Name = collection.Name, ItemDTOs = itemDTOs, UpdateType = UpdateType.IsUnchanged }; return(collectionDTO); }
public async Task TestDeleteCollectionSuccess() { //Should remove the collection var result = await controller.DeleteCollection(2); Assert.IsType <OkObjectResult>(result); OkObjectResult new_res = (OkObjectResult)result; CollectionDTO new_dto = (CollectionDTO)new_res.Value; //Information inside the elimanated CollectionDTO should be equivalent to the requested collection for deletion Assert.Equal("Second_Test_Collection", new_dto.collectionName); Assert.Equal("Second_Mock_Parameter", new_dto.aestheticParameter); Assert.True(2 == new_dto.CollectionId); //Should not be possible to get the collection once its deleted var result2 = await controller.GetCollection(2); Assert.IsType <NotFoundResult>(result2); }
public CollectionDTO InsertCollection(CollectionDTO item) { using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.DatabaseConnectoin)) { connection.Open(); using (SqlCommand command = new SqlCommand()) { command.CommandText = "INSERT INTO [dbo].[Collection] ([Name], [Description], [DisplayOrder]) VALUES (@Name, @Description, @DisplayOrder); SELECT @@IDENTITY AS [ID]"; command.CommandType = CommandType.Text; command.Parameters.AddWithValue("@Name", item.Name); command.Parameters.AddWithValue("@Description", item.Description); command.Parameters.AddWithValue("@DisplayOrder", item.DisplayOrder); item.CollectionID = Convert.ToInt32(command.ExecuteScalar()); } connection.Close(); connection.Dispose(); } return(item); }
public async Task TestPostCollectionSuccess() { CollectionDTO dto = new CollectionDTO(); dto.collectionName = "Post_Test_Collection"; dto.aestheticParameter = "Post_Mock_Parameter"; dto.products = new List <ProductDTO>(); //Should create the new collection var result = await controller.PostCollection(dto); Assert.IsType <CreatedAtActionResult>(result); OkObjectResult new_res = (OkObjectResult)await controller.GetCollection(3); CollectionDTO new_dto = (CollectionDTO)new_res.Value; //Information inside the retrived CollectionDTO should be equivalent to the newly created collection Assert.Equal("Post_Test_Collection", new_dto.collectionName); Assert.Equal("Post_Mock_Parameter", new_dto.aestheticParameter); Assert.True(3 == new_dto.CollectionId); }
public async Task <IActionResult> DeleteProduct([FromRoute] int id, [FromRoute] int idp) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var collection = await collectionRepository.RemoveCollectionProduct(id, idp); if (collection == null) { return(NotFound()); } CollectionDTO dto = new CollectionDTO(); dto.CollectionId = collection.CollectionId; dto.collectionName = collection.collectionName; dto.aestheticParameter = collection.aestheticParameter; dto.products = new List <ProductDTO>(); return(Ok(dto)); }
public CollectionDTO UpdateCollection(CollectionDTO item) { using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.DatabaseConnectoin)) { connection.Open(); using (SqlCommand command = new SqlCommand()) { command.CommandText = "UPDATE [dbo].[Collection] SET [Name] = @Name, [Description] = @Description, [DisplayOrder] = @DisplayOrder WHERE [CollectionID] = @CollectionID"; command.CommandType = CommandType.Text; command.Parameters.AddWithValue("@Name", item.Name); command.Parameters.AddWithValue("@Description", item.Description); command.Parameters.AddWithValue("@DisplayOrder", item.DisplayOrder); command.Parameters.AddWithValue("@CollectionID", item.CollectionID); command.ExecuteNonQuery(); } connection.Close(); connection.Dispose(); } return(item); }
public IEnumerable <CollectionDTO> GetCollection() { List <CollectionDTO> dtos = new List <CollectionDTO>(); foreach (Collection collec in collectionRepository.FindAll()) { CollectionDTO cdto = new CollectionDTO(); cdto.CollectionId = collec.CollectionId; cdto.collectionName = collec.collectionName; cdto.aestheticParameter = collec.aestheticParameter; cdto.products = new List <ProductDTO>(); foreach (CollectionProduct cp in collec.CollectionProducts) { ProductDTO productDTO = productToDTO(cp.Product); cdto.products.Add(productDTO); } dtos.Add(cdto); } return(dtos); }
public async Task TestPutCollectionSuccess() { //Should update Collection CollectionDTO dto = new CollectionDTO(); dto.CollectionId = 1; dto.collectionName = "Test_Collection_Updated"; dto.aestheticParameter = "Second_Mock_Parameter_Updated"; dto.products = new List <ProductDTO>(); var result = await controller.PutCollection(1, dto); Assert.IsType <OkObjectResult>(result); OkObjectResult new_res = (OkObjectResult)await controller.GetCollection(1); CollectionDTO new_dto = (CollectionDTO)new_res.Value; //Information inside the retrived CollectionDTO should be updated Assert.Equal("Test_Collection_Updated", new_dto.collectionName); Assert.Equal("Second_Mock_Parameter_Updated", new_dto.aestheticParameter); Assert.True(1 == new_dto.CollectionId); }