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 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);
            }
        }
Example #3
0
        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 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);
            }
        }
Example #6
0
        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);
        }
Example #8
0
        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
            }
        }