예제 #1
0
        protected void ProcessProposal(XElement input, ISite site)
        {
            MyEntityContext ctx        = Application.Context;
            XAttribute      internalId = input.Attribute("internal-id"); // Value

            IOffer  offer = ctx.Offers.Create();
            IObject obj   = ctx.Objects.Create();

            offer.Object    = obj;
            offer.SiteId    = internalId.Value;
            offer.OfferType = GetOfferType(input);
            offer.Site      = site;

            offer.Created = GetDateTime(input, "creation-date");
            offer.Updated = GetDateTime(input, "last-update-date");

            GetSalesAgent(offer, input);

            // FIXME: The code implies the objects are unique.
            // TODO: Existence check

            obj.PropertyType = GetPropertyType(input);
            obj.Category     = GetCategoryType(input);
            obj.URL          = GetText(input, "url");
            obj.GUID         = GetGUID();

            GetLocationData(obj, input);
            GetPrice(obj, input);
            try {
                obj.ImageURL = GetText(input, "image");
            } catch (InvalidOperationException) {
                obj.ImageURL = null;
            }
            try {
                obj.Rooms = int.Parse(GetText(input, "rooms"));
            } catch (InvalidOperationException) {
                obj.Rooms = 0;
            }
            try {
                obj.RoomsOffered = int.Parse(GetText(input, "rooms-offered"));
            } catch (InvalidOperationException) {
                obj.RoomsOffered = 0;
            }
            try {
                obj.Floor = int.Parse(GetText(input, "floor"));
            } catch (InvalidOperationException) {
                obj.Floor = -1000;
            }

            try {
                obj.FloorTotal = int.Parse(GetText(input, "floors-total"));
            } catch (InvalidOperationException) {
                obj.FloorTotal = -1000;
            }

            try {
                obj.BuildingType = GetBuildingType(input);
            } catch (InvalidOperationException) {
                obj.BuildingType = BuildingEnum.Unknown;
            };
            try {
                obj.BuildingSeries = GetBuildingSeries(input);
            } catch (InvalidOperationException) {
                obj.BuildingSeries = null;
            }
            obj.Description = GetText(input, "description");

            ctx.Add(obj);
            ctx.Add(offer);
        }
예제 #2
0
 public static void InitializeEntityContext()
 {
     Context = new MyEntityContext(ConnectionString);
 }
예제 #3
0
        public bool Process()
        {
            MyEntityContext ctx = Application.Context;

            string nick  = request.Form.user;
            string phone = request.Form.phone;

            Console.WriteLine("---> FORM:" + nick);
            IAgent user     = ctx.Agents.Where(x => x.NickName == nick).FirstOrDefault();
            string register = request.Form["register"];

            MessageModel success = null;

            if (register != null && user != null)
            {
                return(UserBad("Пользователь уже зарегистрирован"));
            }
            else if (register == null && user == null)
            {
                return(UserBad("Пользователь не найден"));
            }
            else if (register != null && user == null)
            {
                // FIXME: Проверки правильности данных не сделаны.

                string password = request.Form.password;
                string repeat   = request.Form.repeat;

                if (password != repeat)
                {
                    return(UserBad("Пароли не совпадают"));
                }

                user              = ctx.Agents.Create();
                user.Name         = request.Form.firstname + " " + request.Form.surname + " " + request.Form.lastname;
                user.PasswordHash = BCryptHelper.HashPassword(password, SALT);
                user.Phone        = request.Form.phone;
                user.GUID         = ImportFromAtlcomru.GetGUID();
                if (request.Form.realtor == "checked")
                {
                    user.Role = RoleEnum.Agent;
                }
                else
                {
                    user.Role = RoleEnum.Buyer;
                }
                user.NickName = nick;
                user.Email    = request.Form.email;
                ctx.Add(user);
                ctx.SaveChanges();
                success = info("Теперь вы зарегистрированы в системе. Можно начинать бояться.",
                               msg: "Успешная регистрация");
            }
            else             // register == null && user != null
            {
                string password = request.Form.password;
                if (!BCryptHelper.CheckPassword(password, user.PasswordHash))
                {
                    return(UserBad("Неправильный пароль"));
                }
                success = info("Ну вот вы и вошли в систему.", msg: "Успешная идентикация");
            }
            // К этому моменту пользователь или аутентифицирован
            // или создан.
            // Установить сессию.

            // Сессии бывают двух типов
            // 1. На время одного сеанса
            // 2. Между сеансами.
            // Мы будем делать 2 из 1.
            // Т.е. в сессии типа 1 собирать (обновлять) данные
            //      зарегистрированного пользователя.

            Session          = new SessionModel(); //Создание новой сессии
            Session["valid"] = true;
            Session["user"]  = user;               // Объект пользователя в сессии
            Session.GUID     = user.GUID;          // Идентификатор сессии пользователя.

            Session["message"] = success;

            Console.WriteLine("Linux rulez!");

            // TODO: Еще надо сделать выход из сессии при разлогигивании. Но пока у нас нет такой команды.

            return(true);
        }
 public static void InitializeEntityContext()
 {
     Context = new MyEntityContext(DB_CONNECTION_STRING);
 }
예제 #5
0
        public bool Process()
        {
            MyEntityContext ctx = Application.Context;

            string nick  = request.Form.user;
            string phone = request.Form.phone;

            Console.WriteLine("---> FORM:" + nick);
            IAgent user     = ctx.Agents.Where(x => x.NickName == nick).FirstOrDefault();
            string register = request.Form["register"];

            MessageModel success = null;

            if (register != null && user != null)
            {
                return(UserBad("Пользователь уже зарегистрирован"));
            }
            else if (register == null && user == null)
            {
                return(UserBad("Пользователь не найден"));
            }
            else if (register != null && user == null)
            {
                // FIXME: Проверки правильности данных не сделаны.

                string password = request.Form.password;
                string repeat   = request.Form.repeat;

                if (password != repeat)
                {
                    return(UserBad("Пароли не совпадают"));
                }

                user = Session.Agent;

                if (Session.Valid)
                {
                    throw new InvalidSession("user must be invalid while registering");
                }
                // Теперь мы из анонимного пользователя делаем зарегистрированного.
                // При этом сохраняется все, что он насмотрел.
                user.Name         = request.Form.firstname + " " + request.Form.surname + " " + request.Form.lastname;
                user.PasswordHash = BCryptHelper.HashPassword(password, SALT);
                user.Phone        = request.Form.phone;
                if (request.Form.realtor == "checked")
                {
                    user.Role = RoleEnum.Agent;
                }
                else
                {
                    user.Role = RoleEnum.Buyer;
                }
                user.NickName = nick;
                user.Email    = request.Form.email;
                ctx.Add(user);
                ctx.SaveChanges();
                success = info("Теперь вы зарегистрированы в системе. Можно начинать бояться.",
                               msg: "Успешная регистрация");
            }
            else             // register == null && user != null
            {
                string password = request.Form.password;
                if (!BCryptHelper.CheckPassword(password, user.PasswordHash))
                {
                    return(UserBad("Неправильный пароль"));
                }
                success = info("Ну вот вы и вошли в систему.", msg: "Успешная идентикация");
            }

            // Session = new SessionModel(); //Создание новой сессии
            Session.Agent = user;               // Объект пользователя в сессии
            Session.GUID  = user.GUID;          // Идентификатор сессии пользователя.

            Session["message"] = success;

            return(true);
        }