public async Task <int> GetByIdUser(string iduser) { if (!IDcustomer.Contains(iduser)) { return(0); } var request = from c in _context.Rents where c.IDcustomer == iduser select c; PagedViewModel <RentRequest> data = new PagedViewModel <RentRequest>() { Items = request.Select(x => new RentRequest() { IdRent = x.IdRent, IDcustomer = x.IDcustomer, End = x.End.Value, idMotel = x.idMotel, Start = x.Start }).ToList(), TotalRecord = await request.CountAsync(), }; var kq = data.Items; return((int)kq.FirstOrDefault().idMotel); }
public async Task <int> UpdateIdCustomer(string id, string idcustomer) { if (!IDcustomer.Contains(idcustomer)) { if (ID.Contains(id)) { var result = _context.Rents.Find(id); if (result != null) { result.IDcustomer = idcustomer; _context.Rents.Update(result); return(await _context.SaveChangesAsync()); } } } return(0); }
public async Task <int> Create(string id, string idcustomer, int idmotel) { if (!getCustomer.Contains(idcustomer) && !getMotel.Contains(idmotel)) { return(0); } if (!ID.Contains(id) && !IDcustomer.Contains(idcustomer) && !IDMotel.Contains(idmotel)) { var rent = new Rent() { IdRent = id, idMotel = idmotel, IDcustomer = idcustomer, Start = DateTime.Now, }; _context.Rents.Add(rent); return(await _context.SaveChangesAsync()); } return(0); }
public async Task <PagedViewModel <RentUser> > GetRoom(string iduser) { if (IDcustomer.Contains(iduser)) { var result = from c in _context.Rents join m in _context.Customers on c.IDcustomer equals m.IDuser where c.IDcustomer == iduser select new { c, m }; var data = new PagedViewModel <RentUser>() { Items = result.Select(x => new RentUser() { idmotel = x.c.idMotel, idrent = x.c.IdRent, iduser = x.c.IDcustomer, Name = x.m.FirstName + " " + x.m.LastName, }).ToList(), TotalRecord = await result.CountAsync(), }; return(data); } return(null); }