public async Task <IActionResult> Create(DepartmentRequestModel requestModel) { return(await ExecuteFunction(async (user) => { var model = AutoMapperUtils.AutoMap <DepartmentRequestModel, Department>(requestModel); return await _departmentService.SaveAsync(model); })); }
public async Task <IActionResult> Update(Guid id, [FromBody] DepartmentRequestModel requestModel) { return(await ExecuteFunction(async (user) => { var model = await _departmentService.GetById(id); if (model == null) { throw new ArgumentException($"Id {id} không tồn tại"); } model = AutoMapperUtils.AutoMap <DepartmentRequestModel, Department>(requestModel, model); return await _departmentService.SaveAsync(model); })); }
static void Main(string[] args) { var db = new BusinessDbContext(); var departmentRepo = new BaseRepository <Department>(db); var departmentService = new BaseService <Department, DepartmentRequestModel, DepartmetnViewModel>(departmentRepo); // we set the fake values here var department = new Department() { Id = Guid.NewGuid().ToString(), Name = "department-" + DateTime.Now.Ticks, Created = DateTime.Now, Modified = DateTime.Now, CreatedBy = "*****@*****.**", ModifiedBy = "*****@*****.**" }; departmentService.Add(department); //now lets fetch those all //var departments = departmentService.GetAllAsync().GetAwaiter().GetResult(); //foreach (var d in departments) //{ // Console.WriteLine(d.Name); //} // now lets search by keyword Console.WriteLine("Input your keyword and press Enter: "); var keyword = Console.ReadLine(); DepartmentRequestModel request = new DepartmentRequestModel(keyword); var result = departmentService.SearchAsync(request).GetAwaiter().GetResult(); Console.WriteLine("Search result : " + result.Item2); foreach (var viewModel in result.Item1) { Console.WriteLine(viewModel.Name); } Console.Read(); }
private void Form_Load(object sender, EventArgs e) { requestModel = new DepartmentRequestModel(""); searchTextBox.DataBindings.Add("Text", requestModel, "Keyword"); }