private async Task ProcessDeleteCommand(RestProcessParameters param, CancellationToken ct) { var restQuery = new RestQueryString(param); var entityDefinition = param.Model.EntitiesByPluralName.SafeGet(restQuery.Root); if (entityDefinition == null) { throw new BadRequestException($"Unable to find an entity definition named {restQuery.Root}."); } if (restQuery.AdditionalQualifier.IsNullOrEmpty()) { throw new BadRequestException($"A delete request must include an id."); } var result = await EntityService.Delete(entityDefinition, restQuery.AdditionalQualifier, ct); if (!result) { Respond(param, new MessageResponse($"Unable to find a {entityDefinition.SingleName} with id {restQuery.AdditionalQualifier}."), StatusCodes.Status404NotFound); return; } Respond(param, null, StatusCodes.Status204NoContent); }
public JsonResult Delete(int id) { EntityService entityService = new EntityService(); entityService.Delete(id); return(Json(new ResponseMessage() { Message = "Đã update thành công", Success = true })); }
public IHttpActionResult DeleteSet(int id) { Set setInDb = _setService.GetById(id); if (setInDb == null) { return(NotFound()); } _setService.Delete(setInDb); return(Ok()); }
/// <summary> /// Delete the specific entity with the id. /// </summary> /// <param name="entityName">"Category"</param> /// <param name="id">"2"</param> public BoolMessage Delete(ScaffoldContext ctx) { BoolMessageItem creationResult = CreateContext(ctx, true, false, false); if (!creationResult.Success) { return(creationResult); } EntityServiceContext entityActionContext = creationResult.Item as EntityServiceContext; // Create the entity using the entity service. EntityService service = new EntityService(); BoolMessage result = service.Delete(entityActionContext); return(result); }
public async Task <IActionResult> Delete(int id) { try { await _entityService.Delete <Model>(id); return(StatusCode(204)); } catch (EntityEmptyId err) { return(StatusCode(401, new { Message = err.Message })); } catch (EntityNotFound err) { return(StatusCode(404, new { Message = err.Message })); } }
public int Delete(int id) { return(EntityService.Delete(id)); }
public JsonResult UpdateInvestments(UpdateInvestmentRequest model) { var transaction = TransactionService.FindTransactionById(model.TransactionId); var workingDate = DateTime.Now; var amount = decimal.Zero; var modelPayments = ConvertToPaymentModel(model); var paymentsToUpdate = BuildInvestmentPaymentSets(modelPayments, transaction.Payments); foreach (var newPayment in paymentsToUpdate["new"]) { var newEntity = new Entity { FullName = newPayment.Remitter.FullName, SourceId = 9 }; EntityService.CreateEntity(newEntity); var payment = new Payment { CaseId = model.CaseId, CaseDetailId = model.CaseDetailId, TransactionId = transaction.TransactionId, CaseNumber = model.CaseNumber, ConceptId = 2, ClassId = 3, Amount = newPayment.Amount, EntityId_RemitTo = newEntity.EntityId, Remitter = newEntity, ToDate = transaction.TransactionDate, TransactionNum = transaction.TransactionId.ToString().PadLeft(9, '0'), CheckBk = 0, StatusId = 2, IssueDate = workingDate, StatusChangeDate = workingDate }; PaymentService.CreatePayment(payment); amount += payment.Amount.GetValueOrDefault(decimal.Zero); } foreach (var changedPayment in paymentsToUpdate["changed"]) { if (changedPayment != null && changedPayment.EntityId_RemitTo == null) { continue; } if (changedPayment == null) { continue; } var existingEntity = EntityService.GetById(changedPayment.EntityId_RemitTo.Value); var payment = PaymentService.FindPaymentById(changedPayment.PaymentId); if (changedPayment.Remitter != null) { existingEntity.FullName = changedPayment.Remitter.FullName; } EntityService.ModifyEntity(existingEntity); payment.Amount = payment.Amount.GetValueOrDefault(decimal.Zero); PaymentService.ModifyPayment(payment); amount += payment.Amount.Value; } foreach (var removedPayment in paymentsToUpdate["removed"]) { if (removedPayment == null) { continue; } var transactionId = removedPayment.TransactionId; PaymentService.Delete(removedPayment.PaymentId); if (removedPayment.EntityId_RemitTo != null) { EntityService.Delete(removedPayment.EntityId_RemitTo); } if (transactionId != null) { TransactionService.Delete(transactionId.Value); } } transaction.TransactionAmount = amount; transaction.Comment = model.Comment; TransactionService.ModifyTransaction(transaction); return(Json(new BasicDataTablesResult(new { Status = "OK" }))); }
private void PrintMenu() { bool exit = false; while (exit != true) { UpdateMenu(); Console.WriteLine(mainMenu); string func = Console.ReadLine(); if (func.Equals("add", StringComparison.OrdinalIgnoreCase)) { Console.Clear(); Configure(); string decision = AskUser("Select enity: student, doctor, mechanic", "[A-Za-z]+"); if (decision.Equals("student", StringComparison.OrdinalIgnoreCase)) { EntityService <Student> .Add(studentReadWrite, "student", GetDataArray("student")); } else if (decision.Equals("doctor", StringComparison.OrdinalIgnoreCase)) { EntityService <Doctor> .Add(doctorReadWrite, "doctor", GetDataArray("doctor")); } else if (decision.Equals("mechanic", StringComparison.OrdinalIgnoreCase)) { EntityService <Mechanic> .Add(mechanicReadWrite, "mechanic", GetDataArray("mechanic")); } } else if (func.Equals("remove", StringComparison.OrdinalIgnoreCase)) { Console.Clear(); string decision = AskUser("Select enity: student, doctor, mechanic", "[A-Za-z]+"); if (decision.Equals("student", StringComparison.OrdinalIgnoreCase)) { EntityService <Student> .Delete(studentReadWrite, AskUser("Enter name", @"[A-Z]?\w+"), AskUser("Enter name", @"[A-Z]?\w+")); } else if (decision.Equals("doctor", StringComparison.OrdinalIgnoreCase)) { EntityService <Doctor> .Delete(doctorReadWrite, AskUser("Enter name", @"[A-Z]?\w+"), AskUser("Enter name", @"[A-Z]?\w+")); } else if (decision.Equals("mechanic", StringComparison.OrdinalIgnoreCase)) { EntityService <Mechanic> .Delete(mechanicReadWrite, AskUser("Enter name", @"[A-Z]?\w+"), AskUser("Enter name", @"[A-Z]?\w+")); } } else if (func.Equals("print", StringComparison.OrdinalIgnoreCase)) { Console.Clear(); string decision = AskUser("Select enity: student, doctor, mechanic", "[A-Za-z]+"); if (decision.Equals("student", StringComparison.OrdinalIgnoreCase)) { EntityService <Student> .Print(studentReadWrite); } else if (decision.Equals("doctor", StringComparison.OrdinalIgnoreCase)) { EntityService <Doctor> .Print(doctorReadWrite); } else if (decision.Equals("mechanic", StringComparison.OrdinalIgnoreCase)) { EntityService <Mechanic> .Print(mechanicReadWrite); } } else if (func.Equals("task", StringComparison.OrdinalIgnoreCase)) { EntityService <Student> .SearchTask(studentReadWrite); } else if (func.Equals("exit", StringComparison.OrdinalIgnoreCase)) { exit = true; break; } else { Console.WriteLine(); continue; } } }
//Process client side data and updates demographic data in the database. public JsonResult Edit(DemographicViewModel demographic) { if (demographic.CaseDetail != null) { var caseDetail = CaseService.FindCaseDetailById(demographic.CaseDetailId); if (caseDetail != null) { if (caseDetail.CaseKey != "00") { var relationship = RelationshipTypeService.GetRelationshipTypes() .Where(x => x.RelationshipType1 == demographic.Relationship && x.WidowCertification == demographic.CaseDetail.Entity.HasWidowCertification) .FirstOrDefault(); caseDetail.RelationshipType = relationship; caseDetail.RelationshipTypeId = relationship.RelationshipTypeId; } #region Entity Information Entity entity = new Entity(); if (!demographic.InsertNewEntity) { entity = EntityService.GetById(Convert.ToInt32(caseDetail.EntityId_Sic)); } entity.FirstName = demographic.CaseDetail.Entity.FirstName.Trim(); entity.MiddleName = demographic.CaseDetail.Entity.MiddleName != null?demographic.CaseDetail.Entity.MiddleName.Trim() : null; entity.LastName = demographic.CaseDetail.Entity.LastName.Trim(); entity.SecondLastName = demographic.CaseDetail.Entity.SecondLastName != null?demographic.CaseDetail.Entity.SecondLastName.Trim() : null; entity.FullName = string.Concat( entity.FirstName + " ", entity.MiddleName.IsNullOrEmpty() ? String.Empty : entity.MiddleName + " ", entity.LastName + " ", entity.SecondLastName.IsNullOrEmpty() ? String.Empty : entity.SecondLastName + " "); entity.CaseNumber = demographic.CaseDetail.CaseNumber; entity.CaseKey = demographic.CaseDetail.CaseKey; entity.SSN = demographic.CaseDetail.Entity.SSN; entity.IDNumber = demographic.CaseDetail.Entity.IDNumber; entity.BirthDate = demographic.CaseDetail.Entity.BirthDate; entity.DeceaseDate = demographic.CaseDetail.Entity.DeceaseDate; entity.MarriageDate = demographic.CaseDetail.Entity.MarriageDate; entity.CivilStatusId = demographic.CaseDetail.Entity.CivilStatusId; entity.IsStudying = demographic.CaseDetail.Entity.IsStudying; entity.SchoolStartDate = demographic.CaseDetail.Entity.SchoolStartDate; entity.SchoolEndDate = demographic.CaseDetail.Entity.SchoolEndDate; entity.HasDisability = demographic.CaseDetail.Entity.HasDisability; entity.OccupationId = demographic.CaseDetail.Entity.OccupationId; entity.MonthlyIncome = demographic.CaseDetail.Entity.MonthlyIncome; entity.IsRehabilitated = demographic.CaseDetail.Entity.IsRehabilitated; entity.IsWorking = demographic.CaseDetail.Entity.IsWorking; entity.IsEmancipated = demographic.CaseDetail.Entity.IsEmancipated; entity.HasWidowCertification = demographic.CaseDetail.Entity.HasWidowCertification; entity.WidowCertificationDate = demographic.CaseDetail.Entity.WidowCertificationDate; entity.ModifiedReasonId = demographic.CaseDetail.Entity.ModifiedReasonId; entity.OtherModifiedReason = demographic.CaseDetail.Entity.OtherModifiedReason; entity.Comments = demographic.CaseDetail.Entity.Comments; entity.Email = demographic.CaseDetail.Entity.Email; entity.HomePhoneNumber = demographic.CaseDetail.Entity.HomePhoneNumber; entity.CellPhoneNumber = demographic.CaseDetail.Entity.CellPhoneNumber; entity.WorkPhoneNumber = demographic.CaseDetail.Entity.WorkPhoneNumber; entity.FaxPhoneNumber = demographic.CaseDetail.Entity.FaxPhoneNumber; entity.OtherPhoneNumber = demographic.CaseDetail.Entity.OtherPhoneNumber; entity.ModifiedBy = WebHelper.GetUserName(); entity.ModifiedDateTime = DateTime.Now; #endregion #region Address Information if (demographic.PostalAddress != null) { Address PostalAddress = demographic.PostalAddress; //Verificar una manera de traer toda la informaicon de coutry / state a traves de ciudad. var city = LocationService.GetAllCities().Where(x => x.CityId == demographic.PostalAddress.CityId).FirstOrDefault(); string state = ""; if (demographic.PostalAddress.StateId != null) { var state1 = LocationService.GetAllStates().Where(x => x.StateId == demographic.PostalAddress.StateId).FirstOrDefault(); state = state1.State1; } var country = LocationService.GetAllCountries().Where(x => x.CountryId == demographic.PostalAddress.CountryId).FirstOrDefault(); PostalAddress.FullAddress = demographic.PostalAddress.Line1 + (demographic.PostalAddress.Line2.IsNullOrEmpty() ? "" : " " + demographic.PostalAddress.Line2.Trim()) + (demographic.PostalAddress.CityId == null ? "" : city.City1 != "Otro" ? " " + city.City1 : " " + demographic.PostalAddress.OtherCity) + (demographic.PostalAddress.StateId == null ? "" : ", " + state) + (demographic.PostalAddress.CountryId == null ? "" : ", " + country.Country1) + (demographic.PostalAddress.ZipCode == null ? "" : " " + demographic.PostalAddress.ZipCode) + (demographic.PostalAddress.ZipCodeExt == null ? "" : "-" + demographic.PostalAddress.ZipCodeExt); PostalAddress.AddressTypeId = AddressTypeService.GetAddressTypes().Where(x => x.AddressType1 == "Postal").Select(x => x.AddressTypeId).FirstOrDefault(); PostalAddress.SourceId = 8; PostalAddress.ModifiedBy = WebHelper.GetUserName(); PostalAddress.ModifiedDateTime = DateTime.Now; if (!demographic.HasAddress) { PostalAddress.CreatedBy = WebHelper.GetUserName(); PostalAddress.CreatedDateTime = DateTime.Now; entity.Addresses.Add(PostalAddress); } else { foreach (var a in demographic.CaseDetail.Entity.Addresses) { if (a.AddressType.AddressType1 == "Postal" && a.AddressId == demographic.PostalAddress.AddressId) { a.Line1 = demographic.PostalAddress.Line1; a.Line2 = demographic.PostalAddress.Line2; a.CityId = demographic.PostalAddress.CityId; a.OtherCity = demographic.PostalAddress.OtherCity; a.StateId = demographic.PostalAddress.StateId; a.CountryId = demographic.PostalAddress.CountryId; a.ZipCode = demographic.PostalAddress.ZipCode; a.ZipCodeExt = demographic.PostalAddress.ZipCodeExt; a.FullAddress = demographic.PostalAddress.FullAddress; a.EntityId = demographic.PostalAddress.EntityId; } } } } #endregion //#region Phone Information //#endregion if (demographic.InsertNewEntity) { entity.SourceId = 8; //SourceId = Entity Sic Source entity.CreatedBy = WebHelper.GetUserName(); entity.CreatedDateTime = DateTime.Now; try { EntityService.CreateEntity(entity); } catch { throw new Exception(); } } else { try { EntityService.ModifyEntity(entity); } catch { throw new Exception(); } } caseDetail.Entity = entity; caseDetail.EntitySic = entity; caseDetail.EntityId = entity.EntityId; caseDetail.EntityId_Sic = entity.EntityId; try { CaseService.UpdateCaseDetail(caseDetail); } catch { EntityService.Delete(entity.EntityId); throw new Exception(); } return(Json(new { Data = demographic.CaseDetail })); } else { throw new Exception(); } } else { throw new Exception(); } }