public YearDTO CreateYear(YearDTO yearDTO, string token) { var exist = _masterService.GetOne <Year>(x => x.YearId == yearDTO.YearId); if (exist == null) { try { var repo = _unitOfWork.GetRepository <Year>(); var newvalue = Mapper.Map <Year>(yearDTO); newvalue.CreationDate = DateTime.Now; newvalue.YearGUID = Guid.NewGuid(); if (newvalue.YearCode == null) { newvalue.YearCode = newvalue.YearId; } //newvalue.CreatedBy = _appUserService.GetUserId(token); repo.Add(newvalue); repo.SaveChanges(); return(Mapper.Map <YearDTO>(newvalue)); } catch (Exception ex) { throw new Exception(ex.Message); } } return(null); }
private async Task <Year> CreatingYear(YearDTO yearDTO) { var spec = await _repo.Get((int)yearDTO.SpecializationID); if (spec == null) { errorsList.Add("Nie odnaleziono specializacji"); return(null); } if (IsInstitute() && spec.Major.InstituteID != GetInstituteID()) { errorsList.Add("Nie możesz dodawać specializacji kierunków do innych wydziałów"); return(null); } var year = _mapper.Map <Year>(yearDTO); year.Specialization = spec; var createdYear = await _repo.Create(year); if (createdYear == null) { errorsList.Add("Nie udało się stworzyć roku"); } return(createdYear); }
//Update Year (async) public async Task <YearDTO> UpdateYearAsync(YearDTO modelDTO) { try { using (var unitOfWork = unitOfWorkFactory.Create()) { YearModel model = _Mapper_ToModel.Map <YearDTO, YearModel>(modelDTO); bool result = unitOfWork.YearRepository.Update(model); YearDTO modelRTN = null; if (result) { await unitOfWork.SaveChangesAsync(); modelRTN = _Mapper_ToDTO.Map <YearModel, YearDTO>(model); } return(modelRTN); } } catch (Exception ex) { LogException(ex); throw ex; } }
public YearDTO CreateYear() { var year = new YearDTO { YearId = _yearService.GetNewYearId() }; return(year); }
public JsonResult Editar(string descripcion, string catalogoId, string itemId) { string result = "duplicate"; switch (catalogoId) { case "m": if (!cliente.GetStates().Any(m => m.Name.ToLower() == descripcion.ToLower())) { StateDTO state = new StateDTO(); state.Name = descripcion; state.Id = Int32.Parse(itemId); cliente.UpdateState(state); result = "success"; } break; case "p": if (!cliente.GetMonths().Any(m => m.Description.ToLower() == descripcion.ToLower())) { MonthDTO month = new MonthDTO(); month.Description = descripcion; month.Id = Int32.Parse(itemId); cliente.UpdateMonth(month); result = "success"; } break; case "n": if (!cliente.GetStatus().Any(m => m.Description.ToLower() == descripcion.ToLower())) { StatusDTO status = new StatusDTO(); status.Description = descripcion; status.Id = Int32.Parse(itemId); cliente.UpdateStatus(status); result = "success"; } break; case "c": if (!cliente.GetYears().Any(m => m.Description.ToLower() == descripcion.ToLower())) { YearDTO year = new YearDTO(); year.Description = descripcion; year.Id = Int32.Parse(itemId); cliente.UpdateYear(year); result = "success"; } break; } return(new JsonResult { Data = new { Result = result } }); }
public void UpdateYear(YearDTO dto) { var b = new ParamDAO(); if (dto.Id > 0) { b.UpdateYear(dto, true); } else { b.UpdateYear(dto, false); } }
public async Task <IHttpActionResult> GetYear(int id) { YearDTO dto = await YearService.SearchSingleYearByIdAsync(id); if (dto != null) { return(Ok(dto)); } else { return(NotFound()); } }
public async Task <IActionResult> CreateYear(int id, YearDTO yearDTO) { yearDTO.SpecializationID = id; if (ValidYearArgs(yearDTO)) { var year = await CreatingYear(yearDTO); if (year != null) { var yearMapped = _mapper.Map <YearSendDTO>(year); return(Ok(yearMapped)); } } return(ResponeError()); }
public async Task <IHttpActionResult> UpdateYear([FromBody] YearDTO YearModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var updatedYear = await YearService.UpdateYearAsync(YearModel); if (updatedYear != null) { return(Ok(updatedYear)); } else { return(NotFound()); } }
public async Task <IHttpActionResult> AddYear([FromBody] YearDTO YearModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var newYearId = await YearService.AddYearAsync(YearModel); if (newYearId != 0) { return(Ok(newYearId)); } else { return(NotFound()); } }
//Add Year (async) public async Task <int> AddYearAsync(YearDTO modelDTO) { try { using (var unitOfWork = unitOfWorkFactory.Create()) { YearModel model = _Mapper_ToModel.Map <YearDTO, YearModel>(modelDTO); unitOfWork.YearRepository.Add(model); //unitOfWork.Repository.Add<YearModel>(model); await unitOfWork.SaveChangesAsync(); return(model.YearId); } } catch (Exception ex) { LogException(ex); throw ex; } }
public IActionResult CreateYear([FromBody] YearDTO value) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var idToken = HttpContext.GetTokenAsync(JwtBearerDefaults.AuthenticationScheme, "access_token"); var token = idToken.Result; var year = _yearService.CreateYear(value, ""); if (year != null) { return(Ok(year)); } return(BadRequest(new { message = "Cannot Create Year" })); } catch (Exception e) { return(BadRequest(e)); } }
private bool ValidYearArgs(YearDTO y) { var f = true; if (y.Name == null) { errorsList.Add("Brak nazwy roku"); f = false; } if (y.Name.Length < 3) { errorsList.Add("Nazwa roku jest za któtka"); f = false; } if (y.Name.Length > 50) { errorsList.Add("Nazwa roku jest za długa"); f = false; } if (y.SpecializationID == null) { errorsList.Add("Brak specializacji"); f = false; } return(f); }
public void UpdateYear(YearDTO year, bool editar) { using (SEDESOLEntities entities = new SEDESOLEntities()) { if (editar) { YEAR existente = entities.YEARs.FirstOrDefault(v => v.Id == year.Id); if (existente != null) { existente.Description = year.Description; entities.SaveChanges(); } } else { YEAR nueva = new YEAR(); nueva.Description = year.Description; nueva.IsActive = true; entities.YEARs.Add(nueva); entities.SaveChanges(); } } }
public void UpdateYear(YearDTO dto) { ParamDAL dal = new ParamDAL(); dal.UpdateYear(dto); }