Exemplo n.º 1
0
        public ActionResult Delete(string id)
        {
            using (var session = DatabaseUtilities.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    try
                    {
                        EntityDB <ImmobiliModel> entityDb = new EntityDB <ImmobiliModel>();
                        string     preQuery   = "Delete from Immobili WHERE 1=1 AND id=@id";
                        SqlCommand preCommand = new SqlCommand(preQuery, session, transaction);
                        preCommand.Parameters.AddWithValue("@id", id);
                        preCommand.ExecuteNonQuery();
                        transaction.Commit();

                        var immobiliList = GetImmobiliList();
                        return(View("Immobili", immobiliList));
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                }
            }
        }
Exemplo n.º 2
0
 public static void Delete(int organisation_id)
 {
     try
     {
         Organisation o = OrganisationDB.GetByID(organisation_id);
         if (o != null)
         {
             DBBase.ExecuteNonResult("DELETE FROM Organisation WHERE organisation_id = " + organisation_id.ToString());
             if (EntityDB.NumForeignKeyDependencies(o.EntityID) == 0)
             {
                 EntityDB.Delete(o.EntityID, false);
             }
         }
     }
     catch (System.Data.SqlClient.SqlException sqlEx)
     {
         if (sqlEx.Errors.Count > 0 && sqlEx.Errors[0].Number == 547) // Assume the interesting stuff is in the first error
         {
             throw new ForeignKeyConstraintException(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name, sqlEx);
         }
         else
         {
             throw;
         }
     }
 }
Exemplo n.º 3
0
 public static void Delete(int person_id)
 {
     try
     {
         Person p = PersonDB.GetByID(person_id);
         if (p != null)
         {
             DBBase.ExecuteNonResult("DELETE FROM Person WHERE person_id = " + person_id.ToString() + "; DBCC CHECKIDENT(Person,RESEED,1); DBCC CHECKIDENT(Person);");
             if (EntityDB.NumForeignKeyDependencies(p.EntityID) == 0)
             {
                 EntityDB.Delete(p.EntityID, false);
             }
         }
     }
     catch (System.Data.SqlClient.SqlException sqlEx)
     {
         if (sqlEx.Errors.Count > 0 && sqlEx.Errors[0].Number == 547) // Assume the interesting stuff is in the first error
         {
             throw new ForeignKeyConstraintException(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name, sqlEx);
         }
         else
         {
             throw;
         }
     }
 }
Exemplo n.º 4
0
        ActionResult Crea(ImmobiliModel immobile)
        {
            using (var session = DatabaseUtilities.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    try
                    {
                        EntityDB <ImmobiliModel> entityDb = new EntityDB <ImmobiliModel>();
                        string preQuery = "SELECT TOP 1 id FROM Immobili " +
                                          " WHERE 1=1  ORDER BY id DESC";

                        // string preQuery = "SELECT * FROM Immobili " +
                        //                 " WHERE 1=1  ORDER BY id DESC LIMIT 1";
                        SqlCommand    preCommand           = new SqlCommand(preQuery, session, transaction);
                        SqlDataReader executeSqlDataReader = preCommand.ExecuteReader();
                        if (executeSqlDataReader.HasRows)
                        {
                            while (executeSqlDataReader.Read())
                            {
                                immobile.Id = long.Parse(executeSqlDataReader["Id"].ToString()) + 1;
                            }
                        }
                        else
                        {
                            immobile.Id = 1;
                        }
                        executeSqlDataReader.Close();
                        string query =
                            "INSERT INTO Immobili (Id, Nome, Descrizione, Mq, Prezzo, TipoImmobile, Posizione) VALUES (@id, @nome, @descrizione, @mq, @prezzo, @tipoImmobile, @posizione)";
                        SqlCommand command = new SqlCommand(query, session, transaction);
                        command.Parameters.AddWithValue("@id", immobile.Id);
                        command.Parameters.AddWithValue("@descrizione", immobile.Descrizione);
                        command.Parameters.AddWithValue("@nome", immobile.Nome);
                        if (!string.IsNullOrEmpty(immobile.Mq))
                        {
                            command.Parameters.AddWithValue("@mq", immobile.Mq);
                        }
                        else
                        {
                            command.Parameters.AddWithValue("@mq", DBNull.Value);
                        }
                        command.Parameters.AddWithValue("@prezzo", immobile.Prezzo);
                        command.Parameters.AddWithValue("@tipoImmobile", immobile.TipoImmobile);
                        command.Parameters.AddWithValue("@posizione", immobile.Posizione);
                        command.ExecuteNonQuery();
                        transaction.Commit();

                        var immobiliList = GetImmobiliList();
                        return(View("Immobili", immobiliList));
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                }
            }
        }
Exemplo n.º 5
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            EntityDB entity = new EntityDB();

            entity.Database.CreateIfNotExists();
        }
Exemplo n.º 6
0
        public void efasync()
        {
            var ar = new[] { new { a = 1 }, new { a = 3 } };

            using (var db = new EntityDB())
            {
                //
            }
        }
Exemplo n.º 7
0
        public ActionResult Edit(string id)
        {
            using (var session = DatabaseUtilities.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    try
                    {
                        EntityDB <ImmobiliModel> entityDb = new EntityDB <ImmobiliModel>();
                        string     query   = "select * from Immobili WHERE 1=1 AND id=@id";
                        SqlCommand command = new SqlCommand(query, session, transaction);
                        command.Parameters.AddWithValue("@id", id);
                        SqlDataReader executeSqlDataReader = command.ExecuteReader();
                        ImmobiliModel immobili             = new ImmobiliModel();
                        while (executeSqlDataReader.Read())
                        {
                            var immobile = new ImmobiliModel()
                            {
                                Id           = long.Parse(executeSqlDataReader["Id"].ToString()),
                                TipoImmobile = executeSqlDataReader["TipoImmobile"].ToString(),
                                Descrizione  = executeSqlDataReader["Descrizione"].ToString(),
                                Mq           = executeSqlDataReader["Mq"].ToString(),
                                Nome         = executeSqlDataReader["Nome"].ToString(),
                                Posizione    = executeSqlDataReader["Posizione"].ToString(),
                                Prezzo       = executeSqlDataReader["Prezzo"].ToString()
                            };
                            List <PictureModel> pic = new List <PictureModel>();
                            string        filepath  = "~/Images/";
                            var           path      = Server.MapPath(filepath + immobile.Id);
                            DirectoryInfo d         = new DirectoryInfo(path);
                            if (d.Exists)
                            {
                                foreach (var file in d.GetFiles())
                                {
                                    pic.Add(new PictureModel()
                                    {
                                        name     = file.Name,
                                        image    = System.IO.File.ReadAllBytes(file.FullName),
                                        selected = file.Name.ToLowerInvariant().Contains("copertina") ? true : false
                                    });
                                }

                                immobile.Picture = pic;
                            }
                            immobili = immobile;
                        }
                        executeSqlDataReader.Close();
                        return(View("ModifyImmobile", immobili));
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                }
            }
        }
Exemplo n.º 8
0
    public static int Insert(int parent_organisation_id, bool use_parent_offernig_prices, int organisation_type_id, int organisation_customer_type_id, string name, string acn, string abn, bool is_debtor, bool is_creditor, string bpay_account, int weeks_per_service_cycle, DateTime start_date, DateTime end_date, string comment, int free_services, bool excl_sun, bool excl_mon, bool excl_tue, bool excl_wed, bool excl_thu, bool excl_fri, bool excl_sat, TimeSpan sun_start_time, TimeSpan sun_end_time, TimeSpan mon_start_time, TimeSpan mon_end_time, TimeSpan tue_start_time, TimeSpan tue_end_time, TimeSpan wed_start_time, TimeSpan wed_end_time, TimeSpan thu_start_time, TimeSpan thu_end_time, TimeSpan fri_start_time, TimeSpan fri_end_time, TimeSpan sat_start_time, TimeSpan sat_end_time, TimeSpan sun_lunch_start_time, TimeSpan sun_lunch_end_time, TimeSpan mon_lunch_start_time, TimeSpan mon_lunch_end_time, TimeSpan tue_lunch_start_time, TimeSpan tue_lunch_end_time, TimeSpan wed_lunch_start_time, TimeSpan wed_lunch_end_time, TimeSpan thu_lunch_start_time, TimeSpan thu_lunch_end_time, TimeSpan fri_lunch_start_time, TimeSpan fri_lunch_end_time, TimeSpan sat_lunch_start_time, TimeSpan sat_lunch_end_time, DateTime last_batch_run)
    {
        int entityID = EntityDB.Insert();

        name         = name.Replace("'", "''");
        acn          = acn.Replace("'", "''");
        abn          = abn.Replace("'", "''");
        bpay_account = bpay_account.Replace("'", "''");
        comment      = comment.Replace("'", "''");
        string sql = "INSERT INTO Organisation (entity_id,parent_organisation_id,use_parent_offernig_prices,organisation_type_id,organisation_customer_type_id,name,acn,abn,is_debtor,is_creditor,bpay_account,weeks_per_service_cycle,start_date,end_date,comment,free_services,excl_sun,excl_mon,excl_tue,excl_wed,excl_thu,excl_fri,excl_sat,sun_start_time,sun_end_time,mon_start_time,mon_end_time,tue_start_time,tue_end_time,wed_start_time,wed_end_time,thu_start_time,thu_end_time,fri_start_time,fri_end_time,sat_start_time,sat_end_time,sun_lunch_start_time,sun_lunch_end_time,mon_lunch_start_time,mon_lunch_end_time,tue_lunch_start_time,tue_lunch_end_time,wed_lunch_start_time,wed_lunch_end_time,thu_lunch_start_time,thu_lunch_end_time,fri_lunch_start_time,fri_lunch_end_time,sat_lunch_start_time,sat_lunch_end_time,last_batch_run) VALUES (" + entityID.ToString() + "," + (parent_organisation_id == 0 ? "NULL" : parent_organisation_id.ToString()) + "," + (use_parent_offernig_prices ? "1" : "0") + "," + organisation_type_id + "," + organisation_customer_type_id + ",'" + name + "'," + "'" + acn + "'," + "'" + abn + "'," + (is_debtor ? "1," : "0,") + (is_creditor ? "1," : "0,") + "'" + bpay_account + "'," + weeks_per_service_cycle + "," + (start_date == DateTime.MinValue ? "NULL" : "'" + start_date.ToString("yyyy-MM-dd HH:mm:ss") + "'") + "," + (end_date == DateTime.MinValue ? "NULL" : "'" + end_date.ToString("yyyy-MM-dd HH:mm:ss") + "'") + "," + "'" + comment + "'," + "" + free_services + "," + (excl_sun ? "1," : "0,") + (excl_mon ? "1," : "0,") + (excl_tue ? "1," : "0,") + (excl_wed ? "1," : "0,") + (excl_thu ? "1," : "0,") + (excl_fri ? "1," : "0,") + (excl_sat ? "1," : "0,") + "'" + sun_start_time.ToString() + "'," + "'" + sun_end_time.ToString() + "'," + "'" + mon_start_time.ToString() + "'," + "'" + mon_end_time.ToString() + "'," + "'" + tue_start_time.ToString() + "'," + "'" + tue_end_time.ToString() + "'," + "'" + wed_start_time.ToString() + "'," + "'" + wed_end_time.ToString() + "'," + "'" + thu_start_time.ToString() + "'," + "'" + thu_end_time.ToString() + "'," + "'" + fri_start_time.ToString() + "'," + "'" + fri_end_time.ToString() + "'," + "'" + sat_start_time.ToString() + "'," + "'" + sat_end_time.ToString() + "'," + "'" + sun_lunch_start_time.ToString() + "'," + "'" + sun_lunch_end_time.ToString() + "'," + "'" + mon_lunch_start_time.ToString() + "'," + "'" + mon_lunch_end_time.ToString() + "'," + "'" + tue_lunch_start_time.ToString() + "'," + "'" + tue_lunch_end_time.ToString() + "'," + "'" + wed_lunch_start_time.ToString() + "'," + "'" + wed_lunch_end_time.ToString() + "'," + "'" + thu_lunch_start_time.ToString() + "'," + "'" + thu_lunch_end_time.ToString() + "'," + "'" + fri_lunch_start_time.ToString() + "'," + "'" + fri_lunch_end_time.ToString() + "'," + "'" + sat_lunch_start_time.ToString() + "'," + "'" + sat_lunch_end_time.ToString() + "'," + (last_batch_run == DateTime.MinValue ? "NULL" : "'" + last_batch_run.ToString("yyyy-MM-dd HH:mm:ss") + "'") + ");SELECT SCOPE_IDENTITY();";

        return(Convert.ToInt32(DBBase.ExecuteSingleResult(sql)));
    }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            using (var entityDB = new EntityDB())
            {
                entityDB.Products.Add(new Product { Name = "Milk" });

                entityDB.SaveChanges();

                foreach (var product in entityDB.Products.ToList())
                {
                    Console.WriteLine(product.Name);
                }
            }
        }
Exemplo n.º 10
0
        public static bool SendMessage(int memberId, string title, string content)
        {
            EntityDB       entity  = new EntityDB();
            member_message message = new member_message()
            {
                content      = content,
                member_id    = memberId,
                state_read   = false,
                sys_datetime = DateTime.Now,
                title        = title,
            };

            entity.member_message.Add(message);
            return(entity.SaveChanges() > 0);
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            using (var entityDB = new EntityDB())
            {
                entityDB.Products.Add(new Product {
                    Name = "Milk"
                });

                entityDB.SaveChanges();

                foreach (var product in entityDB.Products.ToList())
                {
                    Console.WriteLine(product.Name);
                }
            }
        }
Exemplo n.º 12
0
    public static int Insert(int added_by, int title_id, string firstname, string middlename, string surname, string nickname, string gender, DateTime dob)
    {
        if (added_by < 0)
        {
            throw new CustomMessageException("Support staff can not add people to the system. To do this, login as a standard user");
        }

        int entityID = EntityDB.Insert();

        firstname  = firstname.Trim().Replace("'", "''");
        middlename = middlename.Trim().Replace("'", "''");
        surname    = surname.Trim().Replace("'", "''");
        nickname   = nickname.Trim().Replace("'", "''");
        gender     = gender.Replace("'", "''");
        string sql = "INSERT INTO Person (entity_id,added_by,title_id,firstname,middlename,surname,nickname,gender,dob) VALUES (" + entityID.ToString() + "," + added_by + "," + title_id + "," + "'" + firstname + "'," + "'" + middlename + "'," + "'" + surname + "'," + "'" + nickname + "'," + "'" + gender + "'," + (dob == DateTime.MinValue ? "NULL" : "'" + dob.ToString("yyyy-MM-dd HH:mm:ss") + "'") + ");SELECT SCOPE_IDENTITY();";

        return(Convert.ToInt32(DBBase.ExecuteSingleResult(sql)));
    }
Exemplo n.º 13
0
    public static int Insert(string name, int site_type_id, string abn, string acn, string tfn, string asic, bool is_provider, string bank_bpay, string bank_bsb, string bank_account, string bank_direct_debit_userid, string bank_username, decimal oustanding_balance_warning, bool print_epc, bool excl_sun, bool excl_mon, bool excl_tue, bool excl_wed, bool excl_thu, bool excl_fri, bool excl_sat, TimeSpan day_start_time, TimeSpan lunch_start_time, TimeSpan lunch_end_time, TimeSpan day_end_time, DateTime fiscal_yr_end, int num_booking_months_to_get)
    {
        int entityID = EntityDB.Insert();

        name                     = name.Replace("'", "''");
        abn                      = abn.Replace("'", "''");
        acn                      = acn.Replace("'", "''");
        tfn                      = tfn.Replace("'", "''");
        asic                     = asic.Replace("'", "''");
        bank_bpay                = bank_bpay.Replace("'", "''");
        bank_bsb                 = bank_bsb.Replace("'", "''");
        bank_account             = bank_account.Replace("'", "''");
        bank_direct_debit_userid = bank_direct_debit_userid.Replace("'", "''");
        bank_username            = bank_username.Replace("'", "''");
        string sql = "INSERT INTO Site (entity_id,name,site_type_id,abn,acn,tfn,asic,is_provider,bank_bpay,bank_bsb,bank_account,bank_direct_debit_userid,bank_username,oustanding_balance_warning,print_epc,excl_sun,excl_mon,excl_tue,excl_wed,excl_thu,excl_fri,excl_sat,day_start_time,lunch_start_time,lunch_end_time,day_end_time,fiscal_yr_end,num_booking_months_to_get) VALUES (" + entityID + "" + "'" + name + "'," + site_type_id + ",'" + abn + "'," + "'" + acn + "'," + "'" + tfn + "'," + "'" + asic + "'," + (is_provider ? "1," : "0,") + "'" + bank_bpay + "'," + "'" + bank_bsb + "'," + "'" + bank_account + "'," + "'" + bank_direct_debit_userid + "'," + "'" + bank_username + "'," + "" + oustanding_balance_warning + "," + (print_epc ? "1," : "0,") + (excl_sun ? "1," : "0,") + (excl_mon ? "1," : "0,") + (excl_tue ? "1," : "0,") + (excl_wed ? "1," : "0,") + (excl_thu ? "1," : "0,") + (excl_fri ? "1," : "0,") + (excl_sat ? "1," : "0,") + "'" + day_start_time.ToString() + "'," + "'" + lunch_start_time.ToString() + "'," + "'" + lunch_end_time.ToString() + "'," + "'" + day_end_time.ToString() + "'," + "'" + fiscal_yr_end.ToString("yyyy-MM-dd HH:mm:ss") + "'," + "" + num_booking_months_to_get + "" + ");SELECT SCOPE_IDENTITY();";

        return(Convert.ToInt32(DBBase.ExecuteSingleResult(sql)));
    }
Exemplo n.º 14
0
        public override async Task OnActivateAsync()
        {
            Identity      = this.GetPrimaryKeyLong();
            _Logger       = ServiceProvider.GetService <ILoggerFactory>().CreateLogger("Node[" + Identity + "]");
            _CacheClient  = ServiceProvider.GetService <IRedisCacheClient>();
            _IMongoClient = ServiceProvider.GetService <IMongoClient>();
            EntityDB      = ServiceProvider.GetService <IEntityDB>();
            IdGenerator   = ServiceProvider.GetService <IIdGeneratorService>();

            EntityManager = new EntityManager();
            TimerManager  = new TimerManager(this);

            NodeType = await EntityDB.GetNodeType(Identity);

            BatchCahceList = new List <NList>();

            RegisterTimer(ScheduledSave, null, TimeSpan.FromSeconds(0), TimeSpan.FromMilliseconds(TimeUtils.MINITE));

            bool persist = await EntityDB.IsPersist(Identity);

            if (persist)
            {
                IReadOnlyList <Entity> entities = await LoadPersistEntities();

                if (NodeType == NodeType.Grain)
                {
                    foreach (Entity entity in entities)
                    {
                        await Load(entity);
                    }
                }
                else if (NodeType == NodeType.Cache)
                {
                    if (!await CacheExist(Nuid.New(Identity, Identity)))
                    {
                        await SetCacheEntities(entities);
                    }
                }
            }

            await base.OnActivateAsync();
        }
Exemplo n.º 15
0
        public override async Task OnActivateAsync()
        {
            await base.OnActivateAsync();

            _SystemListener = new Dictionary <int, Func <NList, Task> >();
            _Logger         = ServiceProvider.GetService <ILoggerFactory>().CreateLogger("RoleAgent[" + Role + "]");

            Role      = this.GetPrimaryKeyLong();
            _RoleNode = GrainFactory.GetGrain <INode>(Role);
            _RoleId   = Nuid.New(Role, Role);

            if (!await EntityDB.IsPersist(Role))
            {
                await EntityDB.SetNodeType(Role, NodeType.Grain);

                await _RoleNode.Create(_RoleId, Player.TYPE, NList.New());
            }

            await _RoleNode.BindAgent(this);

            RegisterSystem(SystemMsg.CLIENT.CUSTOM, OnRecv_Custom);
        }
Exemplo n.º 16
0
 private static List <ImmobiliModel> GetImmobiliList()
 {
     using (var session = DatabaseUtilities.OpenSession())
     {
         using (var transaction = session.BeginTransaction())
         {
             try
             {
                 EntityDB <ImmobiliModel> entityDb         = new EntityDB <ImmobiliModel>();
                 string               query                = "SELECT * FROM Immobili";
                 SqlCommand           command              = new SqlCommand(query, session, transaction);
                 SqlDataReader        executeSqlDataReader = command.ExecuteReader();
                 List <ImmobiliModel> immobili             = new List <ImmobiliModel>();
                 while (executeSqlDataReader.Read())
                 {
                     var immobile = new ImmobiliModel()
                     {
                         Id           = long.Parse(executeSqlDataReader["Id"].ToString()),
                         TipoImmobile = executeSqlDataReader["TipoImmobile"].ToString(),
                         Descrizione  = executeSqlDataReader["Descrizione"].ToString(),
                         Mq           = executeSqlDataReader["Mq"].ToString(),
                         Nome         = executeSqlDataReader["Nome"].ToString(),
                         Posizione    = executeSqlDataReader["Posizione"].ToString(),
                         Prezzo       = executeSqlDataReader["Prezzo"].ToString()
                     };
                     immobili.Add(immobile);
                 }
                 executeSqlDataReader.Close();
                 return(immobili);
             }
             catch (Exception ex)
             {
                 transaction.Rollback();
                 throw ex;
             }
         }
     }
 }
        public ActionResult RicercaImmobili(FormCollection form)
        {
            string tipoImmobile = form["TipoImmobile"].ToString();
            string posizione    = form["Posizione"].ToString();
            string mq           = form["Mq"].ToString();

            using (var session = DatabaseUtilities.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    try
                    {
                        EntityDB <RicercaImmobiliModel> entityDb = new EntityDB <RicercaImmobiliModel>();
                        string query = "SELECT * FROM Immobili " +
                                       " WHERE 1=1";
                        if (!string.IsNullOrEmpty(tipoImmobile))
                        {
                            query = query + " AND TipoImmobile=@tipoImmobile";
                        }
                        if (!string.IsNullOrEmpty(mq))
                        {
                            query = query + " AND Mq=@mq";
                        }
                        if (!string.IsNullOrEmpty(posizione))
                        {
                            query = query + " AND Posizione=@posizione";
                        }
                        SqlCommand command = new SqlCommand(query, session, transaction);
                        if (!string.IsNullOrEmpty(tipoImmobile))
                        {
                            command.Parameters.AddWithValue("@tipoImmobile", tipoImmobile);
                        }
                        if (!string.IsNullOrEmpty(mq))
                        {
                            command.Parameters.AddWithValue("@mq", mq);
                        }
                        if (!string.IsNullOrEmpty(posizione))
                        {
                            command.Parameters.AddWithValue("@posizione", posizione);
                        }
                        SqlDataReader executeSqlDataReader   = command.ExecuteReader();
                        List <RicercaImmobiliModel> immobili = new List <RicercaImmobiliModel>();
                        while (executeSqlDataReader.Read())
                        {
                            var immobile = new RicercaImmobiliModel()
                            {
                                Id           = long.Parse(executeSqlDataReader["Id"].ToString()),
                                TipoImmobile = executeSqlDataReader["TipoImmobile"].ToString(),
                                Descrizione  = executeSqlDataReader["Descrizione"].ToString(),
                                Mq           = executeSqlDataReader["Mq"].ToString(),
                                Nome         = executeSqlDataReader["Nome"].ToString(),
                                Posizione    = executeSqlDataReader["Posizione"].ToString(),
                                Prezzo       = executeSqlDataReader["Prezzo"].ToString()
                            };
                            immobili.Add(immobile);
                        }

                        //entityDb.DataReaderMapList<RicercaImmobiliModel>(executeSqlDataReader);



                        executeSqlDataReader.Close();
                        return(View(immobili));
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        return(View(new List <RicercaImmobiliModel>()));
                    }
                }
            }
        }
Exemplo n.º 18
0
    private bool IsValidFormScreen()
    {
        string screen = Request.QueryString["screen"];

        return(screen != null && Regex.IsMatch(screen, @"^\d+$") && EntityDB.IDExists(Convert.ToInt32(Request.QueryString["screen"])));
    }
Exemplo n.º 19
0
    private bool IsValidFormID()
    {
        string id = Request.QueryString["id"];

        return(id != null && Regex.IsMatch(id, @"^\d+$") && EntityDB.IDExists(Convert.ToInt32(Request.QueryString["id"])));
    }
Exemplo n.º 20
0
        public ActionResult AggiungiFoto(IEnumerable <HttpPostedFileBase> file, string id)
        {
            string        filepath = "~/Images/";
            var           path     = Server.MapPath(filepath + id);
            DirectoryInfo d        = new DirectoryInfo(path);

            if (!d.Exists)
            {
                d.Create();
            }
            int i = 0;

            foreach (var f in file)
            {
                if (file != null)
                {
                    string pic     = System.IO.Path.GetFileName(f.FileName);
                    string imgPath = System.IO.Path.Combine(path, pic);
                    f.SaveAs(imgPath);
                }
            }


            using (var session = DatabaseUtilities.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    try
                    {
                        EntityDB <ImmobiliModel> entityDb = new EntityDB <ImmobiliModel>();
                        string query = "SELECT * FROM Immobili " +
                                       " WHERE id=@id";
                        SqlCommand command = new SqlCommand(query, session, transaction);
                        command.Parameters.AddWithValue("@id", id);
                        SqlDataReader executeSqlDataReader = command.ExecuteReader();
                        ImmobiliModel immobili             = entityDb.DataReaderMapToList <ImmobiliModel>(executeSqlDataReader);
                        executeSqlDataReader.Close();
                        if (immobili != null)
                        {
                            List <PictureModel> pic = new List <PictureModel>();

                            if (d.Exists)
                            {
                                foreach (var f in d.GetFiles())
                                {
                                    pic.Add(new PictureModel()
                                    {
                                        name  = f.Name,
                                        image = System.IO.File.ReadAllBytes(f.FullName)
                                    });
                                }
                                immobili.Picture = pic;
                            }
                            return(PartialView("RiepilogoImmobile", immobili));
                        }
                        return(PartialView("RiepilogoImmobile", new ImmobiliModel()));
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        ModelState.AddModelError(string.Empty, "Server error try after some time.");
                        return(PartialView("RiepilogoImmobile", new ImmobiliModel()));
                    }
                }
            }
        }
Exemplo n.º 21
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (GetUrlParamType() == UrlParamType.View)
        {
            maintable.Visible = false; // hide this so that we don't send all the page data (all suburbs, etc) to display before it redirects
            Response.Redirect(UrlParamModifier.AddEdit(Request.RawUrl, "type", "edit"));
        }
        else if (GetUrlParamType() == UrlParamType.Edit)
        {
            if (!IsValidFormID())
            {
                HideTableAndSetErrorMessage();
                return;
            }
            ContactAus contact = ContactAusDB.GetByID(GetFormID());
            if (contact == null)
            {
                HideTableAndSetErrorMessage("Invalid contact ID");
                return;
            }

            bool isAddress  = contact.ContactType.ContactTypeGroup.ID == 1;
            bool isTelecoms = contact.ContactType.ContactTypeGroup.ID == 2;
            bool isBedroom  = contact.ContactType.ContactTypeGroup.ID == 3;
            bool isWeb      = contact.ContactType.ContactTypeGroup.ID == 4;
            bool isMobile   = Convert.ToInt32(ddlContactType.SelectedValue) == 30;
            bool isPOBox    = Convert.ToInt32(ddlContactType.SelectedValue) == 37 || Convert.ToInt32(ddlContactType.SelectedValue) == 262;

            bool isEmail   = Convert.ToInt32(ddlContactType.SelectedValue) == 27;
            bool isWebsite = Convert.ToInt32(ddlContactType.SelectedValue) == 28;

            txtAddrLine1.Text = txtAddrLine1.Text.Trim();
            if (isMobile && !System.Text.RegularExpressions.Regex.Replace(txtAddrLine1.Text, "[^0-9]", "").StartsWith("0"))
            {
                SetErrorMessage("Mobile number must start with 0");
                return;
            }
            if (isTelecoms && System.Text.RegularExpressions.Regex.Replace(txtAddrLine1.Text, "[^0-9]", "").Length > 13)
            {
                SetErrorMessage("Phone number can not be more than 13 digits");
                return;
            }
            if (isEmail && !Utilities.IsValidEmailAddress(txtAddrLine1.Text))
            {
                SetErrorMessage("Invalid email address");
                return;
            }
            if (isWebsite && !Utilities.IsValidWebURL(txtAddrLine1.Text))
            {
                SetErrorMessage("Invalid website");
                return;
            }
            if (isPOBox && !Regex.IsMatch(txtAddrLine1.Text, "PO Box", RegexOptions.IgnoreCase) && !Regex.IsMatch(txtAddrLine2.Text, "PO Box", RegexOptions.IgnoreCase))
            {
                SetErrorMessage("The address text must contain \"PO Box\"");
                return;
            }



            ContactAusDB.Update(Convert.ToInt32(lblId.Text),
                                Convert.ToInt32(ddlContactType.SelectedValue),
                                txtFreeText.Text,
                                isTelecoms ? System.Text.RegularExpressions.Regex.Replace(txtAddrLine1.Text, "[^0-9]", "") : txtAddrLine1.Text,
                                txtAddrLine2.Text,
                                txtStreet.Text,
                                isAddress ? Convert.ToInt32(ddlAddressChannelType.SelectedValue) : (contact.AddressChannelType == null ? -1 : contact.AddressChannelType.ID),
                                //isAddress ? Convert.ToInt32(ddlSuburb.SelectedValue)             : (contact.Suburb             == null ? -1 : contact.Suburb.SuburbID),
                                isAddress ? Convert.ToInt32(suburbID.Value) : (contact.Suburb == null ? -1 : contact.Suburb.SuburbID),
                                isAddress ? Convert.ToInt32(ddlCountry.SelectedValue) : (contact.Country == null ? -1 : contact.Country.ID),
                                contact.Site == null ? Convert.ToInt32(Session["SiteID"]) : contact.Site.SiteID,
                                isAddress || isWeb ? chkIsBilling.Checked    : contact.IsBilling,
                                isAddress || isWeb ? chkIsNonBilling.Checked : contact.IsNonBilling);



            //close this window
            maintable.Visible = false; // hide this so that we don't send all the page data (all suburbs, etc) to display before it closes

            bool refresh_on_close = Request.QueryString["refresh_on_close"] != null && Request.QueryString["refresh_on_close"] == "1";

            if (refresh_on_close)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "<script language=javascript>window.opener.location.href=window.opener.location.href;self.close();</script>");
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "<script language=javascript>window.returnValue=false;self.close();</script>");
            }
        }
        else if (GetUrlParamType() == UrlParamType.Add)
        {
            if (!IsValidFormID())
            {
                HideTableAndSetErrorMessage();
                return;
            }

            int entityID = GetFormID();
            if (!EntityDB.IDExists(entityID))
            {
                HideTableAndSetErrorMessage("Invalid entity ID");
                return;
            }


            int contactTypeGroupID = -1;
            UrlParamContactTypeGroup urlParamContactTypeGroup = GetUrlParamContactTypeGroup();
            if (urlParamContactTypeGroup == UrlParamContactTypeGroup.Mailing)
            {
                contactTypeGroupID = 1;
            }
            else if (urlParamContactTypeGroup == UrlParamContactTypeGroup.Telecoms)
            {
                contactTypeGroupID = 2;
            }
            else if (urlParamContactTypeGroup == UrlParamContactTypeGroup.Bedroom)
            {
                contactTypeGroupID = 3;
            }
            else if (urlParamContactTypeGroup == UrlParamContactTypeGroup.Internet)
            {
                contactTypeGroupID = 4;
            }
            else
            {
                HideTableAndSetErrorMessage("Invalid contact_group_type ID");
                return;
            }


            bool isAddress  = contactTypeGroupID == 1;
            bool isTelecoms = contactTypeGroupID == 2;
            bool isBedroom  = contactTypeGroupID == 3;
            bool isWeb      = contactTypeGroupID == 4;
            bool isMobile   = Convert.ToInt32(ddlContactType.SelectedValue) == 30;
            bool isPOBox    = Convert.ToInt32(ddlContactType.SelectedValue) == 37 || Convert.ToInt32(ddlContactType.SelectedValue) == 262;

            bool isEmail   = Convert.ToInt32(ddlContactType.SelectedValue) == 27;
            bool isWebsite = Convert.ToInt32(ddlContactType.SelectedValue) == 28;

            txtAddrLine1.Text = txtAddrLine1.Text.Trim();
            if (isMobile && !System.Text.RegularExpressions.Regex.Replace(txtAddrLine1.Text, "[^0-9]", "").StartsWith("0"))
            {
                SetErrorMessage("Mobile number must start with 0");
                return;
            }
            if (isTelecoms && System.Text.RegularExpressions.Regex.Replace(txtAddrLine1.Text, "[^0-9]", "").Length > 13)
            {
                SetErrorMessage("Phone number can not be more than 13 digits");
                return;
            }
            if (isEmail && !Utilities.IsValidEmailAddress(txtAddrLine1.Text))
            {
                SetErrorMessage("Invalid email address");
                return;
            }
            if (isWebsite && !Utilities.IsValidWebURL(txtAddrLine1.Text))
            {
                SetErrorMessage("Invalid website");
                return;
            }
            if (isPOBox && !Regex.IsMatch(txtAddrLine1.Text, "PO Box", RegexOptions.IgnoreCase) && !Regex.IsMatch(txtAddrLine2.Text, "PO Box", RegexOptions.IgnoreCase))
            {
                SetErrorMessage("The address text must contain \"PO Box\"");
                return;
            }

            int contactID = ContactAusDB.Insert(entityID,
                                                Convert.ToInt32(ddlContactType.SelectedValue),
                                                txtFreeText.Text,
                                                isTelecoms ? System.Text.RegularExpressions.Regex.Replace(txtAddrLine1.Text, "[^0-9]", "") : txtAddrLine1.Text,
                                                txtAddrLine2.Text,
                                                txtStreet.Text,
                                                isAddress ? Convert.ToInt32(ddlAddressChannelType.SelectedValue) : -1,
                                                //isAddress ? Convert.ToInt32(ddlSuburb.SelectedValue)           : -1,
                                                isAddress ? Convert.ToInt32(suburbID.Value) : -1,
                                                isAddress ? Convert.ToInt32(ddlCountry.SelectedValue) : -1,
                                                Convert.ToInt32(Session["SiteID"]),
                                                isAddress || isWeb ? chkIsBilling.Checked    : true,
                                                isAddress || isWeb ? chkIsNonBilling.Checked : true);


            // close this window
            maintable.Visible = false; // hide this so that we don't send all the page data (all suburbs, etc) to display before it closes

            bool refresh_on_close = Request.QueryString["refresh_on_close"] != null && Request.QueryString["refresh_on_close"] == "1";

            if (refresh_on_close)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "<script language=javascript>window.opener.location.href=window.opener.location.href;self.close();</script>");
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "<script language=javascript>window.returnValue=false;self.close();</script>");
            }
        }
        else
        {
            HideTableAndSetErrorMessage("", "Invalid URL Parameters");
        }
    }
Exemplo n.º 22
0
 public UserDAO()
 {
     db = new EntityDB();
 }