public IEnumerable <OrderBO> GetAllUserOrders(Guid userId) { using (ReAgentDBEntities db = new ReAgentDBEntities()) { return(MappingProfilesConfig.Mapper.Map <IEnumerable <OrderBO> >(db.tblOrders.Where(x => x.fk_user == userId))); } }
public int CreateOrder(OrderBO order) { try { using (ReAgentDBEntities db = new ReAgentDBEntities()) { tblOrder tblOrder = db.tblOrders.Add(new tblOrder { details = order.Details, date = DateTime.Now, fk_status = (int)order.Status, fk_user = order.UserId }); db.SaveChanges(); return(tblOrder.pk_id); } } catch (Exception ex) { // TODO: log return(0); } }
public OrderBO GetOrderById(int orderId) { using (ReAgentDBEntities db = new ReAgentDBEntities()) { return(MappingProfilesConfig.Mapper.Map <OrderBO>(db.tblOrders.FirstOrDefault(x => x.pk_id == orderId))); } }
public IEnumerable <UserBO> GetAllUsers() { using (ReAgentDBEntities db = new ReAgentDBEntities()) { return(MappingProfilesConfig.Mapper.Map <IEnumerable <UserBO> >(db.tblUsers)); } }
public Guid Register(UserBO user) { string passwordHash = System.Web.Helpers.Crypto.SHA256(user.Password); Guid verificationToken = Guid.NewGuid(); using (ReAgentDBEntities db = new ReAgentDBEntities()) { db.tblUsers.Add(new tblUser() { pk_id = Guid.NewGuid(), first_name = user.FirstName, last_name = user.LastName, password_hash = passwordHash, email = user.Email, address = user.Address, phone = user.Phone, verification_token = verificationToken, fk_role = (int)UserRole.Client, registration_date = DateTime.Now }); db.SaveChanges(); } return(verificationToken); }
public UserBO GetUserById(Guid id) { using (ReAgentDBEntities db = new ReAgentDBEntities()) { return(MappingProfilesConfig.Mapper.Map <UserBO>(db.tblUsers.FirstOrDefault(x => x.pk_id == id))); } }
public IEnumerable <OrderMessageBO> GetMessagesByOrderId(int orderId) { using (ReAgentDBEntities db = new ReAgentDBEntities()) { return(MappingProfilesConfig.Mapper.Map <IEnumerable <OrderMessageBO> >(db.tblOrderMessages.Where(x => x.fk_order == orderId).OrderBy(x => x.send_date))); } }
public IEnumerable <OrderBO> GetAllOrders() { using (ReAgentDBEntities db = new ReAgentDBEntities()) { return(MappingProfilesConfig.Mapper.Map <IEnumerable <OrderBO> >(db.tblOrders.OrderByDescending(x => x.date))); } }
public UserBO GetUserByEmail(string email) { using (ReAgentDBEntities db = new ReAgentDBEntities()) { return(MappingProfilesConfig.Mapper.Map <UserBO>(db.tblUsers.FirstOrDefault(x => x.email == email))); } }
public bool UserEdit(UserBO user, out string errorMsg) { using (ReAgentDBEntities db = new ReAgentDBEntities()) { tblUser tblUser = db.tblUsers.FirstOrDefault(x => x.pk_id == user.Id); if (tblUser != null) { if (tblUser.email != user.Email && db.tblUsers.Any(x => x.email == user.Email)) { errorMsg = "Пользователь с таким email уже существует"; return(false); } tblUser.email = user.Email; tblUser.first_name = user.FirstName; tblUser.last_name = user.LastName; tblUser.address = user.Address; tblUser.phone = user.Phone; db.SaveChanges(); errorMsg = null; return(true); } errorMsg = "Пользователь не найден"; return(false); } }
public int GetCountNewOrders() { using (ReAgentDBEntities db = new ReAgentDBEntities()) { return(db.tblOrders.Count(x => x.date > NotifyManager.Instance.SyncDate)); } }
public UserRole GetUserRole(Guid userId) { using (ReAgentDBEntities db = new ReAgentDBEntities()) { tblUser user = db.tblUsers.FirstOrDefault(x => x.pk_id == userId); return(user != null ? (UserRole)user.fk_role : UserRole.Client); } }
public bool RemoveUser(Guid userId) { using (ReAgentDBEntities db = new ReAgentDBEntities()) { tblUser user = db.tblUsers.FirstOrDefault(x => x.pk_id == userId); if (user != null) { db.tblUsers.Remove(user); db.SaveChanges(); return(true); } } return(false); }
public Guid?VerifyUser(Guid token) { using (ReAgentDBEntities db = new ReAgentDBEntities()) { tblUser user = db.tblUsers.FirstOrDefault(x => x.verification_token == token); if (user != null) { user.verification_token = null; db.SaveChanges(); return(user.pk_id); } return(null); } }
public OrderBO ChangeStatus(int orderId, OrderStatus status) { using (ReAgentDBEntities db = new ReAgentDBEntities()) { tblOrder order = db.tblOrders.FirstOrDefault(x => x.pk_id == orderId); if (order != null) { order.fk_status = (int)status; db.SaveChanges(); return(MappingProfilesConfig.Mapper.Map <OrderBO>(order)); } } return(null); }
public bool ConfirmRegistration(Guid userId) { using (ReAgentDBEntities db = new ReAgentDBEntities()) { tblUser user = db.tblUsers.FirstOrDefault(x => x.pk_id == userId); if (user != null) { user.verification_token = null; db.SaveChanges(); return(true); } } return(false); }
public void SaveChatMsg(string chatId, string name, string message) { try { using (ReAgentDBEntities db = new ReAgentDBEntities()) { db.tblOrderMessages.Add(new tblOrderMessage { fk_order = Int32.Parse(chatId), user_name = name, message = message, send_date = DateTime.Now }); db.SaveChanges(); } } catch (Exception ex) { //TODO logovani - log4net } }
public UserBO Login(string email, string password, out string errorMsg) { var hash = System.Web.Helpers.Crypto.SHA256(password); using (ReAgentDBEntities db = new ReAgentDBEntities()) { tblUser user = db.tblUsers.FirstOrDefault(x => x.email == email && x.password_hash == hash); if (user != null) { if (user.verification_token.HasValue) { errorMsg = "Email не верифицирован"; return(null); } errorMsg = null; return(MappingProfilesConfig.Mapper.Map <UserBO>(user)); } errorMsg = "Имя пользователя или пароль указаны неверно."; return(null); } }