public int Update(DbEmployee employee) { var employ = _context.Find <DbEmployee>(employee.Id); if (employ == null) { return(0); } if (employ.Name != null) { employ.Name = employee.Name; } if (employ.Family != null) { employ.Family = employee.Family; } if (employ.Mname != null) { employ.Mname = employee.Mname; } if (employ.Year != null) { employ.Year = employee.Year; } if (employ.Email != null) { employ.Email = employee.Email; } var b = _context.Update(employ); return(b); }
public Employee(DbEmployee dbEmployee) { this.EmployeeId = dbEmployee.EmployeeId; this.Name = dbEmployee.Name; this.Alias = dbEmployee.Alias; this.Manager = dbEmployee.Manager; }
public void AddEmployee(string surName, string firstName, string patronymic, DateTime dateOfBirth, string docSeries, string docNumber, string Position, DbDepartment currentDep) { var employee = new DbEmployee(); employee.DepartmentID = currentDep.ID; employee.SurName = surName; employee.FirstName = firstName; employee.DateOfBirth = dateOfBirth; employee.Position = Position; if (!string.IsNullOrEmpty(patronymic)) { employee.Patronymic = patronymic; } if (!string.IsNullOrEmpty(docSeries)) { employee.DocSeries = docSeries; } if (!string.IsNullOrEmpty(docNumber)) { employee.DocNumber = docNumber; } using (var context = new Context()) { context.DbEmployees.Add(employee); context.SaveChanges(); } }
public Employee(DbEmployee employee, Action refreshTable, string depName) { this.employee = employee; this.refreshTable = refreshTable; this.depName = depName; InitializeComponent(); if (employee == null) { this.Text = "AddNewEmployee"; EmployeeGroupBox.Text = "Добавить данные"; } else { this.Text = "EditEmployee"; EmployeeGroupBox.Text = "Редактировать данные"; } DepartmentComboBox.DataSource = departmentRepository.GetAllDepartments(); DepartmentComboBox.ValueMember = "ID"; DepartmentComboBox.DisplayMember = "Name"; LineLengthSetting(); InitializeTextBox(); DepartmentComboBox.SelectedIndex = DepartmentComboBox.FindStringExact(depName); }
/// <inheritdoc/> public void UpdateEmployee(DbEmployee employee) { _db.Execute("UPDATE employee SET " + "\"lastName\" = @LastName, " + "\"firstName\" = @FirstName, " + "\"middleName\" = @MiddleName, " + "\"birthDate\" = @BirthDate " + "WHERE \"id\" = @Id", employee); }
public ActionResult Put(DbEmployee employee) { var result = _service.Update(employee); if (result > 0) { return(Ok()); } return(BadRequest()); }
public async Task <bool> AddEmployee(DbEmployee employee) { var client = _clientFactory.CreateClient("api"); var response = await client.PostAsJsonAsync("Employee", employee); if (response.IsSuccessStatusCode) { return(true); } return(false); }
public string GetIdentity() { string ID = ""; using (var entity = new DbEmployee()) { var list = entity.Employees.ToList(); if (list.Count == 0) { ID = "NV00000000"; } else { int temp; ID = "NV"; temp = Convert.ToInt32(list[list.Count - 1].ID.ToString().Substring(2, 8)); temp = temp + 1; if (temp < 10) { ID = ID + "0000000"; } else if (temp < 100) { ID = ID + "000000"; } else if (temp < 1000) { ID = ID + "00000"; } else if (temp < 10000) { ID = ID + "0000"; } else if (temp < 100000) { ID = ID + "000"; } else if (temp < 1000000) { ID = ID + "00"; } else if (temp < 10000000) { ID = ID + "0"; } ID = ID + temp.ToString(); } return(ID); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager <IdentityUser> userManager, ILogger <Startup> log) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseMigrationsEndPoint(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); if (userManager.FindByNameAsync("Kitchen@HotelHost").Result == null || userManager.FindByNameAsync("Reception@HotelHost").Result == null || userManager.FindByNameAsync("Restaurant@HotelHost").Result == null) { DbEmployee.CreateKitchenEmployee(userManager, log); Thread.Sleep(2000); DbEmployee.CreateReceptionEmployee(userManager, log); Thread.Sleep(2000); DbEmployee.CreateRestaurantEmployee(userManager, log); } app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapRazorPages(); }); }
public async Task <IActionResult> Register([FromBody] RegisterRequest model) { var employee = new DbEmployee { FirstName = model.FirstName, LastName = model.LastName, Email = model.Email, Office = model.Office }; var result = await _userManager.CreateAsync(employee, model.Password); if (!result.Succeeded) { return(BadRequest(result.Errors.First().Description)); } var responseId = new RegisterResponse { Id = employee.Id }; return(Ok(responseId)); }
public async Task ProcessNewhireEvent(string eventId, string personName, string personId, string personNumber) { Console.WriteLine($"Processing new hire event: EventId: {eventId}, PersonName: {personName}, PersonId: {personId}, PersonNumber: {personNumber}"); var employeeToAdd = new DbEmployee() { PersonName = personName, PersonId = personId, PersonNumber = personNumber }; var eventToAdd = new DbEvent() { UniqueEventId = eventId }; try { //Default transaction level is read committed using (var trans = await _dbContext.Database.BeginTransactionAsync().ConfigureAwait(false)) { _dbContext.Employees.Add(employeeToAdd); _dbContext.Events.Add(eventToAdd); //Read Committed transaction will fail once this event ID has been added already. ReadCommitted is the default transaction level await _dbContext.SaveChangesAsync().ConfigureAwait(false); await trans.CommitAsync().ConfigureAwait(false); } Console.WriteLine("Completed successfully :)"); } catch (Exception ex) { _logger.LogError(ex.InnerException.Message); } }
public IEnumerable <Employee> Update([FromBody] IEnumerable <Employee> employees) { //パラメータの表示 employees.All(e => { Debug.WriteLine($"Id:{e.Id}, Code:{e.Code}, Name:{e.Name}, Birthday:{e.Birthday}, Age:{e.Age}"); Debug.WriteLine($"e.IsValid():{e.IsValid()}"); e.ErrorMessage.All(d => { Debug.WriteLine($"key:{d.Key}, ErrorMessage:{d.Value}"); return(true); }); return(true); }); #if true //DB以外の入力チェック(サーバ版) Debug.WriteLine("サーバの入力チェックを実施します。"); employees.All(e => { e.ErrorMessage.Clear(); e.Validation(); return(true); }); Debug.WriteLine("サーバの入力チェックを実施しました。"); //サーバエラーの証拠を入れる。そうしないとどっちで動いていたのかわからない。 employees.All(e => { Dictionary <string, string> em = new Dictionary <string, string>(); foreach (var(key, value) in e.ErrorMessage) { em[key] = value + "(サーバチェック)"; } e.ErrorMessage = em; //e.ErrorMessage.Keys.All(k => //{ // e.ErrorMessage[k] = e.ErrorMessage[k] + "(サーバ)"; // return true; //}); /* * System.InvalidOperationException: 'Collection was modified; enumeration operation may not execute.' */ return(true); }); Thread.Sleep(400); var dbEmployee = new DbEmployee(); var fromEmp = employees.FirstOrDefault <Employee>(); if (fromEmp.IsValid()) { Facade.ObjectCopy(fromEmp, dbEmployee); } Debug.WriteLine($"dbEmployee.Name={dbEmployee.Name}"); Debug.WriteLine($"dbEmployee.Age={dbEmployee.Age}"); return(employees); #else return(Enumerable.Range(1, 3).Select(index => new Employee { Id = index, Code = $"{index:D6}", Name = "hogehoge", Birthday = DateTime.Now.AddYears(-7) })); #endif }
public async Task <Result> Handle(Command request, CancellationToken cancellationToken) { var exists = await _context.Set <SuUser>().AnyAsync(o => o.UserName.ToLower() == request.UserName.ToLower(), cancellationToken); if (exists) { throw new RestException(HttpStatusCode.BadRequest, "message.STD00004", "label.SURT06.Username"); } var studentType = await _context.GetParameterValue <string>("SuUserType", "Student", cancellationToken); var saveResult = new Result(); DbEmployee employee = null; string password = string.Empty; employee = await _context.Set <DbEmployee>().FirstOrDefaultAsync(o => o.CompanyCode == _user.Company && o.EmployeeCode == request.EmployeeCode, cancellationToken); password = employee.EmployeeCode; request.CreatedBy = _user.UserName; request.CreatedDate = DateTime.Now; request.CreatedProgram = _user.ProgramCode; request.UpdatedBy = _user.UserName; request.UpdatedDate = DateTime.Now; request.UpdatedProgram = _user.ProgramCode; var result = await _identity.CreateUserAsync(request, password); var userType = new SuUserType { UserId = result.UserId, CompanyCode = _user.Company, UserType = request.UserType }; if (request.UserType == studentType) { userType.StudentId = request.StudentId; } else { userType.EmployeeCode = request.EmployeeCode; } _context.Set <SuUserType>().Add(userType); await _context.SaveChangesAsync(cancellationToken); saveResult.haveEmail = false; if (request.UserType != studentType && employee != null && !string.IsNullOrWhiteSpace(employee?.Email)) { try { var param = new Dictionary <string, string>(); param.Add("[UserName]", request.UserName); param.Add("[Password]", password); await _email.SendEmailWithTemplateAsysnc("SU002", employee.Email, null, param); saveResult.haveEmail = true; } catch (Exception ex) { _logger.LogError(ex, "SURT06 send create user email fail."); } } saveResult.Id = result.UserId; return(saveResult); }
/// <inheritdoc/> public void NewEmployee(DbEmployee employee) { _db.Execute("INSERT INTO employee VALUES (@Id, @LastName, @FirstName, @MiddleName, @BirthDate)", employee); }
public int Add(DbEmployee employee) { var b = _context.Create(employee); return(b); }
public bool InsertEmployee(EmployeeModels model, ref string msg) { bool result = true; using (DataContext cxt = new DataContext()) { var _isExits = cxt.dbEmployee.Any(x => x.Email.Equals(model.Email) && x.IsActive); if (_isExits) { result = false; msg = "Địa chỉ email đã tồn tại"; } else { using (var transaction = cxt.Database.BeginTransaction()) { try { DbEmployee item = new DbEmployee(); string id = Guid.NewGuid().ToString(); item.ID = id; item.FirstName = model.FirstName; item.LastName = model.LastName; item.Name = model.Name; item.Phone = model.Phone; item.Email = model.Email; item.Password = model.Password; item.Country = model.Country; item.BirthDate = model.BirthDate; item.Address = model.Address; item.Gender = model.Gender; item.MaritalStatus = model.MaritalStatus; item.IsActive = model.IsActive; item.IsSupperAdmin = model.IsSupperAdmin; item.CreatedDate = DateTime.Now; item.CreatedUser = model.CreatedUser; item.ModifiedDate = DateTime.Now; item.ModifiedUser = model.CreatedUser; cxt.dbEmployee.Add(item); cxt.SaveChanges(); transaction.Commit(); } catch (Exception ex) { NSLog.Logger.Error("Không thể thêm nhân viên. Làm ơn kiểm tra lại!", ex); result = false; msg = "Không thể cập nhập cho nhân viên này. Làm ơn kiểm tra lại!"; transaction.Rollback(); } finally { if (cxt != null) { cxt.Dispose(); } } } } } return(result); }