public async Task UpdateAsync(int id, FeatureDTO featureDTO) { var feature = mapper.Map <Feature>(featureDTO); feature.Id = id; await unitOfWork.Features.UpdateAsync(feature); }
public void PostFeature([FromBody] FeatureDTO feature) { using (new TimeMeasure("Post Features")) { System.Diagnostics.Debug.WriteLine("Lige før feature query.................................................."); string query = "INSERT into Feature_Table(Feature_ID, Product_ID, EN_Name, DK_Name, Value, Measure_ID, EN_MeasureValue, DK_MeasureValue, EN_Description, DK_Description) VALUES (@Feature_ID, @Product_ID, @EN_Name, @DK_Name, @Value, @Measure_ID, @EN_MeasureValue, @DK_MeasureValue, @EN_Description, @DK_Description)"; SqlConnection connection = new SqlConnection(connectionString); using (SqlCommand insertCommand = new SqlCommand(query, connection)) { connection.Open(); insertCommand.Parameters.AddWithValue("@Feature_ID", feature.featureId); insertCommand.Parameters.AddWithValue("@Product_ID", feature.productId); insertCommand.Parameters.AddWithValue("@EN_Name", feature.en_name); insertCommand.Parameters.AddWithValue("@DK_Name", feature.dk_name); insertCommand.Parameters.AddWithValue("@Value", feature.value); insertCommand.Parameters.AddWithValue("@Measure_ID", feature.measureId); insertCommand.Parameters.AddWithValue("@EN_MeasureValue", feature.en_measureValue); insertCommand.Parameters.AddWithValue("@DK_MeasureValue", feature.dk_measureValue); insertCommand.Parameters.AddWithValue("@EN_Description", feature.en_description); insertCommand.Parameters.AddWithValue("@DK_Description", feature.dk_description); System.Diagnostics.Debug.WriteLine("Lige før execute query.................................................."); insertCommand.ExecuteNonQuery(); connection.Close(); } } }
public FeatureViewModel(FeatureDTO feature, IList <FeatureValueDTO> values, string value) { FeatureId = feature.Id; Name = feature.Name; Title = feature.Title ?? feature.Name; Notes = feature.Notes; Value = value; Type = feature.ValuesType; ExtendedValue = feature.ExtendedValue; if (values != null && values.Count > 0) { long intValue = ValueAsInt ?? 0; Items = values.OrderBy(v => v.Order) .Select(v => new SelectListItemEx { Selected = v.Id == intValue, Text = v.Value, ParentValue = v.ExtendedValue, Value = v.Id.ToString() }) .ToList(); } else { Items = new List <SelectListItemEx>(); } }
public async Task EditDraftFeature(Guid tenderGuid, FeatureDTO featureDTO) { var savedFeature = await Context.DraftFeatures .FirstOrDefaultAsync(i => i.Tender.Guid == tenderGuid && i.StringId == featureDTO.StringId); Context.Entry(savedFeature).CurrentValues.SetValues(featureDTO); await Context.SaveChangesAsync(); }
public async Task Should_raise_error_when_toggling_an_nonexisting_feature_as_active() { var dto = new FeatureDTO(name: "buttonIsBlue", isActive: true); await _featureDomainService.TogleFeature(dto); await _mediator.Received(1).Publish(Arg.Is <ErrorNotification>(d => d.Error.Equals(DomainMessageError.NonExistentFeature))); }
public FeatureUpdatedEvent(FeatureDTO featureDTO) { EventId = Guid.NewGuid(); TimeStamp = DateTime.UtcNow; Id = featureDTO.Id; Name = featureDTO.Name; Description = featureDTO.Description; Price = featureDTO.Price; }
public static DraftFeature ToDraft(this FeatureDTO source) { return(source == null ? null : new DraftFeature(source) { Values = source.Values?.Select(x => x.ToDraft()).ToList() }); }
//POST /api/items public IHttpActionResult CreateFeature(FeatureDTO featureDTO) { var feature = Mapper.Map <FeatureDTO, Feature>(featureDTO); _context.Features.Add(feature); _context.SaveChanges(); featureDTO.Id = feature.Id; return(Created(new Uri(Request.RequestUri + "/" + feature.Id), featureDTO)); }
public void Delete(FeatureDTO feature) { FeatureDAL featureToDelete = new FeatureDAL() { ID = feature.ID }; _unitOfWork.Feature.Delete(featureToDelete); _unitOfWork.Save(); }
public async Task <string> AddFeature(Guid tenderGuid, FeatureDTO featureDTO) { throw new NotImplementedException(); //var tender = await Context.Tenders.Where(m => m.Guid == tenderGuid).FirstOrDefaultAsync(); //var mapper = new FeatureMapper(); //var feature = mapper.Map(featureDTO); //tender.Features.Add(feature); //await Context.SaveChangesAsync(); //return feature.StringId; }
public async Task Should_not_add_feature_if_there_is_an_existing_feature_with_same_name() { var dto = new FeatureDTO(name: "buttonIsBlue", isActive: false); var entity = new Feature("buttonIsBlue", true); _featureRepository.GetByName("buttonIsBlue").Returns(entity); var feature = await _featureDomainService.AddFeature(dto); _featureRepository.Received(0).Add(feature); }
public async Task <string> AddDraftFeature(Guid tenderGuid, FeatureDTO draftFeatureDTO) { var tender = await Context.DraftTenders.FirstOrDefaultAsync(m => m.Guid == tenderGuid); var draftFeature = draftFeatureDTO.ToDraft(); tender.Features.Add(draftFeature); await Context.SaveChangesAsync(); return(draftFeature.StringId); }
public async Task Should_update_feature_if_there_is_an_existing_feature_with_same_name() { var dto = new FeatureDTO(name: "buttonIsBlue", isActive: false); var entity = new Feature("buttonIsBlue", true); _featureRepository.GetByName("buttonIsBlue").Returns(entity); var feature = await _featureDomainService.AddFeature(dto); feature.IsActive.Should().BeFalse(); }
//PUT /api/items/{id} public IHttpActionResult UpdateFeature(int id, FeatureDTO featureDTO) { var featureFromDB = _context.Features.SingleOrDefault(f => f.Id == id); if (featureFromDB == null) { NotFound(); } Mapper.Map(featureDTO, featureFromDB); return(Ok(featureDTO)); }
public async Task EditFeature(Guid tenderGuid, FeatureDTO featureDTO) { var savedFeature = await Context.Features .Include(f => f.Values) .FirstOrDefaultAsync(i => i.Tender.Guid == tenderGuid && i.StringId == featureDTO.StringId); // update values from DTO Context.Entry(savedFeature).CurrentValues.SetValues(featureDTO); Context.Replace(savedFeature.Values, featureDTO.Values); await Context.SaveChangesAsync(); }
public void Put([FromBody] FeatureDTO feature) { var newStories = feature.Stories; for (int i = 0; i < newStories.Count; i++) { newStories[i].FeatureId = feature.ID; _storyService.UpdateStory(newStories[i]); } _featureService.Put(feature); }
public async Task Should_add_feature() { var dto = new FeatureDTO(name: "buttonIsBlue", isActive: false); var feature = await _featureDomainService.AddFeature(dto); using (new AssertionScope()) { dto.ValidationResult.Errors.Should().BeEmpty(); _featureRepository.Received(1).Add(feature); } }
public async Task Should_toggle_feature_as_inactive() { var dto = new FeatureDTO(name: "buttonIsBlue", isActive: false); var existingFeature = new Feature(name: "buttonIsBlue", isActive: true); _featureRepository.GetByName("buttonIsBlue").Returns(existingFeature); await _featureDomainService.TogleFeature(dto); existingFeature.IsActive.Should().BeFalse(); }
public void Delete([FromBody] FeatureDTO feature) { var newStories = feature.Stories; if (newStories != null) { for (int i = 0; i < newStories.Count; i++) { newStories[i].FeatureId = null; _storyService.UpdateStory(newStories[i]); } } _featureService.Delete(feature); }
public async Task Should_raise_error_if_feature_is_invalid() { var dto = new FeatureDTO(name: "", isActive: false); var feature = await _featureDomainService.AddFeature(dto); using (new AssertionScope()) { dto.ValidationResult.Errors.Should().NotBeEmpty(); _featureRepository.Received(0).Add(feature); dto.ValidationResult.Errors.Select(d => d.ErrorMessage).ToArray().Contains(DomainMessageError.FeatureNameCannotBeNulllOrEmpty); await _mediator.Received(1).Publish(Arg.Is <ErrorNotification>(d => d.Error.Equals(DomainMessageError.FeatureNameCannotBeNulllOrEmpty))); } }
public void Post(FeatureDTO feature) { _unitOfWork.Feature.Create(new FeatureDAL() { ID = feature.ID, Name = feature.Name, Description = feature.Description, StateID = feature.StateID, State = feature.State, OwnerID = feature.OwnerID, Owner = feature.Owner, PriorityID = feature.PriorityID, Time = feature.Time }); _unitOfWork.Save(); }
private static Feature UpdateFeature(Feature existingFeature, FeatureDTO featureDTO) { if (featureDTO.IsActive == existingFeature.IsActive) { return(existingFeature); } if (featureDTO.IsActive) { existingFeature.Enable(); } else { existingFeature.Disable(); } return(existingFeature); }
public List <FeatureDTO> GetFeatureByProdId(string id, string connectionString) //Get a specific Product form the database searching on Prod_ID { List <FeatureDTO> features = new List <FeatureDTO>(); using (new TimeMeasure("GetFeatureByProdId")) { string query = "SELECT * FROM Feature_Table WHERE Product_ID = '" + id + "'"; using (SqlConnection databaseConnection = new SqlConnection(connectionString)) { databaseConnection.Open(); using (SqlCommand selectCommand = new SqlCommand(query, databaseConnection)) { using (SqlDataReader reader = selectCommand.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { int featureLineId = reader.GetInt32(0); string featureId = reader.GetString(1); string productId = reader.GetString(2); string en_name = reader.GetString(3); string dk_name = reader.GetString(4); string value = reader.GetString(5); string measureId = reader.GetString(6); string en_measureValue = reader.GetString(7); string dk_measureValue = reader.GetString(8); string en_description = reader.GetString(9); string dk_description = reader.GetString(10); FeatureDTO feature = new FeatureDTO(featureLineId, featureId, productId, en_name, dk_name, value, measureId, en_measureValue, dk_measureValue, en_description, dk_description); features.Add(feature); } } } } databaseConnection.Close(); } return(features); } }
public async Task TogleFeature(FeatureDTO featureDTO) { if (!featureDTO.IsValid()) { await NotifyValidationErrors(featureDTO); return; } var existingFeature = await _featureRepository.GetByName(featureDTO.Name); if (existingFeature != null) { UpdateFeature(existingFeature, featureDTO); } else { await NotifyError(DomainMessageError.NonExistentFeature); } }
public async Task <Feature> AddFeature(FeatureDTO featureDTO) { if (!featureDTO.IsValid()) { await NotifyValidationErrors(featureDTO); return(null); } var existingFeature = await _featureRepository.GetByName(featureDTO.Name); if (existingFeature != null) { return(UpdateFeature(existingFeature, featureDTO)); } var feature = new Feature(featureDTO.Name, featureDTO.IsActive); _featureRepository.Add(feature); return(feature); }
public void UpdateSameFeature([FromBody] FeatureDTO feature) { using (new TimeMeasure("UpdateSameFeature")) { System.Diagnostics.Debug.WriteLine("Inde i update same Feature...................................."); string query = "UPDATE Feature_Table SET " + "Feature_ID = @Feature_ID, " + "Product_ID = @Product_ID, " + "EN_Name = @EN_Name, " + "DK_Name = @DK_Name, " + "Value = @Value, " + "Measure_ID = @Measure_ID, " + "EN_MeasureValue = @EN_MeasureValue, " + "DK_MeasureValue = @DK_MeasureValue, " + "EN_Description = @EN_Description, " + "DK_Description = @DK_Description " + "WHERE Feature_ID = @Feature_ID " + "AND Product_ID = @Product_ID"; SqlConnection connection = new SqlConnection(connectionString); using (SqlCommand insertCommand = new SqlCommand(query, connection)) { connection.Open(); insertCommand.Parameters.AddWithValue("@Feature_ID", feature.featureId); insertCommand.Parameters.AddWithValue("@Product_ID", feature.productId); insertCommand.Parameters.AddWithValue("@EN_Name", feature.en_name); insertCommand.Parameters.AddWithValue("@DK_Name", feature.dk_name); insertCommand.Parameters.AddWithValue("@Value", feature.value); insertCommand.Parameters.AddWithValue("@Measure_ID", feature.measureId); insertCommand.Parameters.AddWithValue("@EN_MeasureValue", feature.en_measureValue); insertCommand.Parameters.AddWithValue("@DK_MeasureValue", feature.dk_measureValue); insertCommand.Parameters.AddWithValue("@EN_Description", feature.en_description); insertCommand.Parameters.AddWithValue("@DK_Description", feature.dk_description); insertCommand.ExecuteNonQuery(); connection.Close(); } } }
public FeatureDTO GetFeatureByFeatureIdAndProdId(string featureId, string prodId) { using (new TimeMeasure("GetFeatureByFeatureIdAndProdId")) { FeatureDTO feature = new FeatureDTO(); string query = "SELECT * FROM Feature_Table WHERE Feature_ID = '" + featureId + "' AND Product_ID = '" + prodId + "'"; using (SqlConnection databaseConnection = new SqlConnection(connectionString)) { databaseConnection.Open(); using (SqlCommand selectCommand = new SqlCommand(query, databaseConnection)) { using (SqlDataReader reader = selectCommand.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { feature.featureId = reader.GetString(1); feature.productId = reader.GetString(2); feature.en_name = reader.GetString(3); feature.dk_name = reader.GetString(4); feature.value = reader.GetString(5); feature.measureId = reader.GetString(6); feature.en_measureValue = reader.GetString(7); feature.dk_measureValue = reader.GetString(8); feature.en_description = reader.GetString(9); feature.dk_description = reader.GetString(10); } } } } databaseConnection.Close(); } return(feature); } }
private static FeatureDTO CreateFeatureDTO(Feature feat, bool withDetails = false) { var feature = new FeatureDTO { Id = feat.Id, No = feat.No.ToString(), Description = feat.Description, Release = feat.Release, Status = feat.Status.ToString(), EditType = feat.EditType.ToString(), AddedToRoadmap = feat.AddedToRoadmap, LastModified = feat.LastModified, ValueHash = feat.ValuesHash, Changes = feat.Changes?.OrderByDescending(x => x.Date).Select(x => new ChangeSetDTO { Type = x.Type.ToString(), Date = x.Date, Changes = x.Changes?.Select(z => new ChangeDTO { Property = z.Property, OldValue = z.OldValue, NewValue = z.NewValue, }).ToList() }).ToList(), TagCategories = feat.FeatureTags?.GroupBy(x => x.Tag.Category).Select(x => new TagCategoryDTO { Category = x.Key.ToString(), Tags = x.Select(z => z.Tag.Name).ToList() }).ToList() }; if (withDetails) { feature.Details = feat.Details; feature.MoreInfo = feat.MoreInfo; } return(feature); }
public async Task <IHttpActionResult> PostFeature(Feature feature) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Features.Add(feature); await db.SaveChangesAsync(); // new code // load author name db.Entry(feature).Reference(x => x.Author).Load(); var dto = new FeatureDTO() { Id = feature.Id, FeatName = feature.FeatName, isComplete = feature.isComplete }; return(CreatedAtRoute("DefaultApi", new { id = feature.Id }, dto)); }
public void Post([FromBody] FeatureDTO feature) { _featureService.Post(feature); }