public async Task <IActionResult> PutUserModel([FromRoute] int id, [FromBody] UserModel userModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != userModel.UserId) { return(BadRequest()); } _context.Entry(userModel).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserModelExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutMembership([FromRoute] int id, [FromBody] Membership membership) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != membership.MembershipId) { return(BadRequest()); } _context.Entry(membership).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MembershipExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <GetCustomerDTO> Handle(PostCustomerCommand request, CancellationToken cancellationToken) { if (request.Data.Attributes.gender == "male") { request.Data.Attributes.sex = Gender.male; } else if (request.Data.Attributes.gender == "female") { request.Data.Attributes.sex = Gender.female; } _context.customers.Add(request.Data.Attributes); await _context.SaveChangesAsync(); return(new GetCustomerDTO { Message = "Successfully Added", Success = true, Data = new CustomerData { Id = request.Data.Attributes.Id, Full_name = request.Data.Attributes.full_name, Username = request.Data.Attributes.username, Birthdate = request.Data.Attributes.birthdate, Password = request.Data.Attributes.password, Gender = Enum.GetName(typeof(Gender), request.Data.Attributes.sex), Email = request.Data.Attributes.email, Phone_number = request.Data.Attributes.phone_number } }); }
public async Task <CustomerDTO> Handle(DeleteCustomerCommand request, CancellationToken cancellationToken) { var data = await _context.customers.FindAsync(request.Id); if (data == null) { return(null); } _context.customers.Remove(data); await _context.SaveChangesAsync(); return(new CustomerDTO { Message = "Successfull", Success = true }); }
public async Task <GetCustomerPayDTO> Handle(PostCustomerPayCommand request, CancellationToken cancellationToken) { _context.customerPayCard.Add(request.Data.Attributes); await _context.SaveChangesAsync(); return(new GetCustomerPayDTO { Message = "Success retreiving data", Success = true, Data = new CustomerPayData { Id = request.Data.Attributes.Id, Customer_id = request.Data.Attributes.customer_id, Name_on_card = request.Data.Attributes.name_on_card, Exp_month = request.Data.Attributes.exp_month, Exp_year = request.Data.Attributes.exp_year, Postal_code = request.Data.Attributes.postal_code, Credit_card_number = request.Data.Attributes.credit_card_number } }); }
/// <summary> /// 添加 /// </summary> /// <param name="model">实体对象</param> /// <returns></returns> public async Task <int> AddAsync(T model) { _db.Entry(model).State = EntityState.Added; return(await _db.SaveChangesAsync()); }