public async Task <IActionResult> AddCode(CodeForAddDto CodeForAddDto) { // ItemForAddDto.Name = ItemForAddDto.Name.ToLower(); // if (await _repo.UserExists(ItemForAddDto.Name)) // return BadRequest("Tài khoản đã tồn tại"); CodeForAddDto.CodeID = GenerateCodes(); CodeForAddDto.Status = true; var CodeToCreate = _mapper.Map <Code>(CodeForAddDto); _repo.Add(CodeToCreate); await _repo.SaveAll(); var CodeNew = await _repo.GetCode(CodeToCreate.CodeID); foreach (var item in CodeForAddDto.CourseId) { CodeCourse codeCourse = new CodeCourse { CourseId = item, CodeID = CodeNew.Id }; _repo.Add(codeCourse); await _repo.SaveAll(); } return(Ok(CodeToCreate)); }
public IActionResult Random() { var guid = Guid.NewGuid().ToString().Replace("-", "").ToLower().Remove(6).ToUpper(); _codeRepository.Add(new Code { LoginCode = guid }); return(Content(guid)); }
public GeneralResponse AddCode(AddCodeRequestOld request) { GeneralResponse response = new GeneralResponse(); try { Code code = new Code(); code.ID = Guid.NewGuid(); code.CreateDate = PersianDateTime.Now; code.CreateEmployee = _employeeRepository.FindBy(request.CreateEmployeeID); code.Center = _centerRepository.FindBy(request.CenterID); code.CodeName = request.CodeName; code.RowVersion = 1; #region If Duplicate, send Error message Infrastructure.Querying.Query query = new Infrastructure.Querying.Query(); Criterion criterion = new Criterion("CodeName", code.CodeName, CriteriaOperator.Equal); query.Add(criterion); if (_codeRepository.FindBy(query).Count() > 0) { Code exitstCode = _codeRepository.FindBy(query).FirstOrDefault(); //response.ErrorMessages.Add(String.Format("این پیش شماره قبلاً برای مرکز مخابراتی «{0}» به ثبت رسیده است.", exitstCode.Center.CenterName)); response.ErrorMessages.Add("RegisteredKey" + exitstCode.Center.CenterName + "ThisPerfixKey"); return(response); } #endregion #region Update Center Of Customers if exist any IEnumerable <Customer> customers = _customerRepository.FindByPhoneCode(code.CodeName); Center center = _centerRepository.FindBy(request.CenterID); if (customers.Count() > 0) { foreach (Customer customer in customers) { customer.Center = center; _customerRepository.Save(customer); } } #endregion #region Validation if (code.GetBrokenRules().Count() > 0) { foreach (BusinessRule businessRule in code.GetBrokenRules()) { response.ErrorMessages.Add(businessRule.Rule); } return(response); } #endregion _codeRepository.Add(code); _uow.Commit(); ////response.success = true; } catch (Exception ex) { response.ErrorMessages.Add(ex.Message); } return(response); }