public void LoadModifySpecializationPage(SpecializationDTO specialization) { IWindowManager manager = new WindowManager(); AddSpecializationViewModel add = new AddSpecializationViewModel(specialization); manager.ShowDialog(add, null, null); Reload(); }
public SpecializationDTO GetById(int id) { List <SpecializationDTO> specializations = new List <SpecializationDTO>(); try { using (SqlConnection connection = Database.getConnection()) { SqlCommand cmd = new SqlCommand("GetSpecializationById", connection) { CommandType = CommandType.StoredProcedure }; connection.Open(); cmd.Parameters.AddWithValue("@specializationID", id); foreach (DbDataRecord record in cmd.ExecuteReader()) { SpecializationDTO specialization = new SpecializationDTO ( record.GetInt32(record.GetOrdinal("id")) ); specializations.Add(specialization); } connection.Close(); } return(specializations[0]); } catch (Exception e) { Console.WriteLine(e); throw; } }
private async Task <Specialization> CreatingSpecialization(SpecializationDTO specDTO) { var major = await _repo.Get((int)specDTO.MajorID); if (major == null) { errorsList.Add("Nie odnaleziono kierunku"); return(null); } if (IsInstitute() && major.InstituteID != GetInstituteID()) { errorsList.Add("Nie możesz dodawać kierunków do innych wydziałów"); return(null); } var spec = _mapper.Map <Specialization>(specDTO); spec.Major = major; var createdSpec = await Create(spec); if (createdSpec != null) { return(createdSpec); } errorsList.Add("Nie udało się stworzyć specjalizacji"); return(null); }
public List <SpecializationDTO> GetAll() { List <SpecializationDTO> specializations = new List <SpecializationDTO>(); string query = "SELECT * FROM Specialization"; try { using (SqlConnection connection = Database.getConnection()) { connection.Open(); SqlCommand cmd = new SqlCommand(query, connection); foreach (DbDataRecord record in cmd.ExecuteReader()) { var specialization = new SpecializationDTO ( record.GetInt32(record.GetOrdinal("id")), record.GetString(record.GetOrdinal("name")), record.GetString(record.GetOrdinal("description")), record.GetInt32(record.GetOrdinal("healthPoints")), record.GetInt32(record.GetOrdinal("attackPoints")) ); specializations.Add(specialization); } connection.Close(); } } catch (Exception e) { Console.WriteLine(e); throw; } return(specializations); }
public static Specialization Convert(this SpecializationDTO specializationDto) { var spec = new Specialization { ItemId = specializationDto.ItemId, IsDeleted = specializationDto.IsDeleted, Updated = specializationDto.Updated, CorrectorId = specializationDto.CorrectorId, ShortName = specializationDto.ShortName, FullName = specializationDto.FullName, Level = specializationDto.Level, KeyPersonel = specializationDto.KeyPersonel }; var department = specializationDto.Department?.Convert(); if (department != null) { spec.Department = department.IsDeleted ? Department.Unknown : department; } else { spec.Department = Department.Unknown; } return(spec); }
public async Task <ActionResult> Create([FromBody] SpecializationDTO dto) { try { var spec = dto.ConceptSpecialization(); var created = await manager.CreateAsync(spec); return(Ok(SpecializationDTO.From(created))); } catch (FormatException fe) { logger.LogError("Malformed Specialization:{@Specialization} Error:{Error}", dto, fe.Message); return(BadRequest(CRUDError.From("Malformed Specialization.UniversalId."))); } catch (ArgumentException ae) { logger.LogError("Invalid create Specialization model. Model:{@Model} Error:{Error}", dto, ae.Message); return(BadRequest(CRUDError.From($"{nameof(Specialization)} is missing or incomplete."))); } catch (LeafRPCException le) { return(StatusCode(le.StatusCode, CRUDError.From(le.Message))); } catch (Exception e) { logger.LogError("Failed to create Specialization:{@Specialization} Error:{Error}", dto, e.ToString()); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public GroupModel(GroupDTO group) : base(group) { this.cathedra = group.Cathedra; this.specialization = group.Specialization; this.cathedraId = group.CathedraID; this.specializationId = group.SpecializationID; }
public static Specialization CastToDAL(SpecializationDTO specialization) { return(new Specialization() { specId = specialization.specId, specName = specialization.specName, specKindId = specialization.specKindId, }); }
public Specialization MapToSpecialization(SpecializationDTO specializationDTO) { return(new Specialization() { Name = specializationDTO.Name, EngName = specializationDTO.EngName, ShortName = specializationDTO.ShortName }); }
public static void Delete(SpecializationDTO Specialization) { using (ArmyBaseContext db = new ArmyBaseContext()) { var toDelete = db.Specializations.Where(x => x.Id == Specialization.Id).FirstOrDefault(); toDelete.IsDisabled = true; db.SaveChanges(); } }
public Specialization Post(SpecializationDTO value) { Specialization model = new Specialization() { Name = value.Name, Description = value.Description }; return(ISpecializationRepository.Create(model)); }
public BaseDTO map(Specialization specialization, IList <string> propertyNeeded) { var specializationDTO = new SpecializationDTO { SpecializationID = (StringListHelper.IsExist(propertyNeeded, "SpecializationID")) ? specialization.SpecializationID : -1, SpecializationName = (StringListHelper.IsExist(propertyNeeded, "SpecializationName")) ? specialization.SpecializationName : null, }; return(specializationDTO); }
public HttpResponseMessage GetDetailsSpec(int id) { SpecializationDTO dTO = new SpecializationDTO(); dTO = BL.SpecializationLogic.GetDetailsSpecialization(id); if (dTO != null) { return(Request.CreateResponse(HttpStatusCode.OK, dTO)); } return(Request.CreateResponse(HttpStatusCode.NotFound)); }
public void Delete(SpecializationDTO specialization) { IWindowManager manager = new WindowManager(); DeleteConfirmationViewModel modify = new DeleteConfirmationViewModel(); bool? showDialogResult = manager.ShowDialog(modify, null, null); if (showDialogResult != null && showDialogResult == true) { SpecializationService.Delete(specialization); } Reload(); }
public async Task <IActionResult> UpdateSpec(int id, SpecializationDTO specDTO) { var updatedSpec = await UpdatingSpec(id, specDTO); if (updatedSpec != null) { var specMapped = _mapper.Map <SpecializationSendDTO>(updatedSpec); return(Ok(specMapped)); } return(ResponeError()); }
public AddSpecializationViewModel(SpecializationDTO specialization) { AvailableEquipment = new BindableCollection <EquipmentDTO>(EquipmentService.GetAll().ToList()); BindableCollection <EquipmentDTO> abc = new BindableCollection <EquipmentDTO>(); foreach (var a in AvailableEquipment) { bool toDelete = false; foreach (var b in a.Specialization) { if (b.Id == specialization.Id) { toDelete = true; } } if (toDelete) { abc.Add(a); } } AvailableEquipment.RemoveRange(abc); ActualEquipment = new BindableCollection <EquipmentDTO>(EquipmentService.GetAll().Where(x => x.Specialization.Where(y => y.Id == specialization.Id).Any()).ToList()); AvailablePermissions = new BindableCollection <PermissionDTO>(PermissionService.GetAll().ToList()); BindableCollection <PermissionDTO> abc1 = new BindableCollection <PermissionDTO>(); foreach (var a in AvailablePermissions) { bool toDelete = false; foreach (var b in a.Specialization) { if (b.Id == specialization.Id) { toDelete = true; } } if (toDelete) { abc1.Add(a); } } AvailablePermissions.RemoveRange(abc1); ActualPermissions = new BindableCollection <PermissionDTO>(PermissionService.GetAll().Where(x => x.Specialization.Where(y => y.Id == specialization.Id).Any()).ToList()); IsEdit = true; ButtonLabel = "Edit"; this.toEdit = specialization; Name = toEdit.Name; Description = toEdit.Description; NotifyOfPropertyChange(() => Name); NotifyOfPropertyChange(() => Description); }
public static List <SpecializationDTO> ListSpecializationToListSpecializationDTO(List <Specialization> specializations) { List <SpecializationDTO> specializationDTOs = new List <SpecializationDTO>(); foreach (Specialization specilizationIt in specializations) { SpecializationDTO specializationDTO = new SpecializationDTO { Id = specilizationIt.Id, Name = specilizationIt.SpecializationName }; specializationDTOs.Add(specializationDTO); } return(specializationDTOs); }
public async Task <IActionResult> AddNewSpecialization(AddSpecializationModel model) { SpecializationDTO newItem = new SpecializationDTO() { nameSpecialization = model.nameSpecialization, Speciality = model.nameSpeciality, nameCathedra = model.nameCathedra }; await specialization.Create(newItem); return(RedirectToAction("GetSpecialization", "EducationalDepartment")); }
public async Task <OperationDetails> Create(SpecializationDTO itemDTO) { Specialization newItem = new Specialization() { nameSpecialization = itemDTO.nameSpecialization, ID_Speciality = Database.RSpecialities.Get(itemDTO.Speciality).IdSpeciality, ID_Cathedra = Database.RCathedra.Get(itemDTO.nameCathedra).IdCathedra, }; Database.RSpecialization.Create(newItem); await Database.Save(); return(new OperationDetails(true, "Registration success", "")); }
public Specialization Put(int id, SpecializationDTO value) { Specialization model = ISpecializationRepository.Get(id); if (value.Name != null) { model.Name = value.Name; } if (value.Description != null) { model.Description = value.Description; } return(ISpecializationRepository.Update(model)); }
public async Task <IActionResult> CreateSpecjalizations(int id, SpecializationDTO specDTO) { specDTO.MajorID = id; if (ValidSpecArgs(specDTO)) { var spec = await CreatingSpecialization(specDTO); if (spec != null) { var specMapped = _mapper.Map <SpecializationSendDTO>(spec); return(Ok(specMapped)); } } return(ResponeError()); }
public async Task <ActionResult> Update(Guid id, [FromBody] SpecializationDTO dto) { try { if (dto == null) { return(BadRequest(CRUDError.From("Specialization is missing."))); } if (dto.SpecializationGroupId == default) { return(BadRequest(CRUDError.From("Specialization.SpecializationGroupId is required."))); } if (string.IsNullOrWhiteSpace(dto.UiDisplayText)) { return(BadRequest(CRUDError.From("Specialization.UiDisplayText is required."))); } if (string.IsNullOrWhiteSpace(dto.SqlSetWhere)) { return(BadRequest(CRUDError.From("Specialization.SqlSetWhere is required."))); } dto.Id = id; var spec = dto.ConceptSpecialization(); var updated = await specializationService.Update(spec); if (updated == null) { return(NotFound()); } return(Ok(SpecializationDTO.From(updated))); } catch (FormatException fe) { logger.LogError("Malformed Specialization:{@Specialization} Error:{Error}", dto, fe.Message); return(BadRequest(CRUDError.From("Malformed Specialization.UniversalId."))); } catch (LeafDbException le) { return(StatusCode(le.StatusCode, CRUDError.From(le.Message))); } catch (Exception e) { logger.LogError("Could not update Specialization:{@Specialization} Error:{Error}", dto, e.ToString()); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public static string Edit(SpecializationDTO Specialization, List <EquipmentDTO> equipment, List <PermissionDTO> permissions) { using (ArmyBaseContext db = new ArmyBaseContext()) { string error = null; var toModify = db.Specializations.Include("Permission").Include("Equipment").Where(x => x.Id == Specialization.Id).FirstOrDefault(); toModify.Name = Specialization.Name; toModify.Description = Specialization.Description; var assignEquipments = new List <Equipment>(); foreach (var e in equipment) { var result1 = db.Equipments.Where(x => x.Id == e.Id).FirstOrDefault(); assignEquipments.Add(result1); } var assignPermissions = new List <Permission>(); foreach (var p in permissions) { var result1 = db.Permissions.Where(x => x.Id == p.Id).FirstOrDefault(); assignPermissions.Add(result1); } toModify.Permission = assignPermissions; toModify.Equipment = assignEquipments; var context = new ValidationContext(toModify, null, null); var result = new List <ValidationResult>(); Validator.TryValidateObject(toModify, context, result, true); foreach (var x in result) { error = error + x.ErrorMessage + "\n"; } if (error == null) { db.SaveChanges(); } return(error); } }
public SpecializationDTO FindSpecialization(string name) { Specialization item = Database.RSpecialization.Get(name); SpecializationDTO itemDTO = null; if (item != null) { itemDTO = new SpecializationDTO(); itemDTO.ID_Specialization = item.ID_Specialization; itemDTO.nameSpecialization = item.nameSpecialization; itemDTO.Speciality = Database.RSpecialities.GetAll().Where(x => x.IdSpeciality == item.ID_Speciality).SingleOrDefault().specialityName; itemDTO.nameCathedra = Database.RCathedra.GetAll().Where(x => x.IdCathedra == item.ID_Cathedra).SingleOrDefault().cathedraName; itemDTO.nameFaculty = Database.RFaculties.GetAll().Where(x => x.IdFaculty == Database.RCathedra.GetAll().Where(x => x.IdCathedra == item.ID_Cathedra).SingleOrDefault().ID_faculty).SingleOrDefault().facultyName; } return(itemDTO); }
private async Task <Specialization> UpdatingSpec(int id, SpecializationDTO specDTO) { var spec = await _repo.Get(id); if (spec == null) { errorsList.Add("Specializacja nie istnieje"); return(null); } if (IsInstitute() && GetInstituteID() != spec.Major.Institute.ID) { errorsList.Add("Nie możesz mdyfikować kierunków z innego wydziału"); return(null); } Tools.CopyValues(spec, specDTO); if (IsSuperUser() && specDTO.MajorID != null) { var major = await _repo.Get <Major>((int)specDTO.MajorID); if (major == null) { errorsList.Add("Wydział nie istnieje"); return(null); } spec.Major = major; } var UpdatedSpec = await _repo.Update(spec); if (UpdatedSpec != null) { return(UpdatedSpec); } errorsList.Add("Nie udało się zmodyfikować kierunku"); return(null); }
private bool ValidSpecArgs(SpecializationDTO s) { var f = true; if (s.Name == null) { errorsList.Add("Brak nazwy specjalizacji"); f = false; } if (s.Name.Length < 3) { errorsList.Add("Nazwa specjalizacji jest za któtka"); f = false; } if (s.Name.Length > 50) { errorsList.Add("Nazwa specjalizacji jest za długa"); f = false; } if (s.MajorID == null) { errorsList.Add("Brak kierunku"); f = false; } return(f); }
public Specialization GetById(int id) { SpecializationDTO specialization = _specializationContext.GetById(id); return(new Specialization(specialization.Id, specialization.Name)); }
public static void AddSpecialization(SpecializationDTO specializationDTO) { db.Specializations.Add(SpecializationCast.CastToDAL(specializationDTO)); }
public static void RemoveSpecialization(SpecializationDTO specializationDTO) { db.Specializations.Remove(SpecializationCast.CastToDAL(specializationDTO)); }
public SpecializationModel(SpecializationDTO city) { this.Id = city.Id; this.Name = city.Name; }