protected void BtnSearch_Click(object sender, EventArgs e) { TakeOrderInfoViewModel infoModel = new TakeOrderInfoViewModel(); string phoneId = this.phoneNumbers.Value; string userName = this.userNames.Value; IResult result = this.Presenter.GetInfo(phoneId, userName); this.TakeIResult(result, ref infoModel); if (result is ErrorResult) { this.NotyTakeOrder.Update(this); this.UserRepeter.DataSource = null; this.PhonesRepeter.DataSource = null; this.OrderRepeater.DataSource = null; this.UserRepeter.DataBind(); this.PhonesRepeter.DataBind(); this.OrderRepeater.DataBind(); } else { this.UserRepeter.DataSource = new UserViewModel[] { infoModel.UserInfo }; this.PhonesRepeter.DataSource = infoModel.PhonesInfo; this.OrderRepeater.DataSource = infoModel.OrdersInfo; this.UserRepeter.DataBind(); this.PhonesRepeter.DataBind(); this.OrderRepeater.DataBind(); } }
public IResult GetInfo(string phoneId, string username) { TakeOrderInfoViewModel model = new TakeOrderInfoViewModel(); if (string.IsNullOrWhiteSpace(phoneId) && string.IsNullOrWhiteSpace(username)) { return(this.ErrorResult("Error: Both phone and username are empty.")); } else if (!string.IsNullOrWhiteSpace(phoneId) && !string.IsNullOrWhiteSpace(username)) { return(this.ErrorResult("Error: Both phone and username have data. Please use one of them.")); } else if (!string.IsNullOrWhiteSpace(phoneId)) { var order = this.Data.PhoneNumberOrders.All() .Where(o => o.PhoneNumber == phoneId) .OrderByDescending(o => o.ActionDate).FirstOrDefault(); if (order == null) { return(this.ErrorResult("Message: There isn't order with this phone. It is never use.")); } model = this.GetInfoForUser(order.UserId); } else if (!string.IsNullOrWhiteSpace(username)) { var userId = this.Data.Users.All() .Where(x => x.UserName == username) .Select(x => x.Id) .FirstOrDefault(); if (userId == null) { return(this.ErrorResult("Message: There is no such user.")); } model = this.GetInfoForUser(userId); } return(this.DataResult(model)); }
private TakeOrderInfoViewModel GetInfoForUser(string userId) { var model = new TakeOrderInfoViewModel(); model.UserInfo = this.Data.Users.All() .Where(x => x.Id == userId) .Project().To <UserViewModel>() .FirstOrDefault(); model.OrdersInfo = this.Data.PhoneNumberOrders.All() .Where(o => o.UserId == userId) .Project().To <OrdersViewModel>() .OrderByDescending(o => o.ActionDate) .ToList(); model.PhonesInfo = this.Data.Phones.All() .Where(p => p.UserId == userId) .OrderByDescending(p => p.ModifiedOn) .Project().To <PhoneInfoViewModel>() .ToList(); return(model); }