Esempio n. 1
0
        public ActionResult AddUnit(AddPropertyVM model)
        {
            if (Session["UserName"] == null)
            {
                return(RedirectToAction("Index", "Account"));
            }
            ViewBag.ReportTitle = "Add New unit";

            //var selectedRoles = model.Roles.Where(x => x.IsChecked).Select(x => x.ID).ToList();
            //var selectedCompanies = model.Companies.Where(x => x.IsChecked).Select(x => x.ID).ToList();
            PropertyManager.AddUnit(model);
            return(RedirectToAction("Index"));
        }
Esempio n. 2
0
        public ActionResult Add()
        {
            // add new user
            if (Session["UserName"] == null)
            {
                return(RedirectToAction("Index", "Account"));
            }
            ViewBag.ReportTitle = "Add new Property";

            AddPropertyVM model = new AddPropertyVM();

            model.AllStatus  = GetSelectListItems((short)Helpers.Helpers.ListType.allStatus);
            model.AllCompany = GetSelectListItems((short)Helpers.Helpers.ListType.company);
            return(View(model));
        }
Esempio n. 3
0
        public static void AddUnit(AddPropertyVM model)
        {
            using (SqlConnection connection = new SqlConnection(Helpers.Helpers.GetAppConnectionString()))
            {
                try
                {
                    // Create the user record.
                    SqlCommand cmd = new SqlCommand("", connection);
                    connection.Open();

                    //add Unit 0 by default
                    cmd.CommandText = "Insert into tblPropertyUnit (UnitName, PropertyID, Notes) values ('" + model.Address + "', " + model.PropertyID + ", '" + model.note + "');SELECT SCOPE_IDENTITY();";
                    int unitID = int.Parse(cmd.ExecuteScalar().ToString());
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
                finally
                {
                    connection.Close();
                }
            }
        }
Esempio n. 4
0
        public static void Add(AddPropertyVM model)
        {
            using (SqlConnection connection = new SqlConnection(Helpers.Helpers.GetAppConnectionString()))
            {
                try
                {
                    // Create the user record.
                    SqlCommand cmd = new SqlCommand("", connection);
                    connection.Open();

                    SqlParameter IDParameter = new SqlParameter("@PropertyID", SqlDbType.Int);
                    IDParameter.Direction = ParameterDirection.Output;
                    cmd.Parameters.Add(IDParameter);
                    StringBuilder sb = new StringBuilder();
                    sb.Append("insert into tblProperty (");
                    sb.Append("PurchaseDate ,");
                    sb.Append("Address ,");
                    sb.Append("City ,");
                    sb.Append("Zip ,");
                    sb.Append("PurchasePrice ,");
                    sb.Append("PropertyTaxYearPayment ,");
                    sb.Append("PropertyTaxMailingAddress ,");
                    sb.Append("PropertyTaxDueDate ,");
                    sb.Append("StatusID ,");
                    sb.Append("note ,");
                    sb.Append("InterestRate ,");
                    sb.Append("LoanAmount ,");
                    sb.Append("InsuranceCompany ,");
                    sb.Append("InsurancePremium ,");
                    sb.Append("InsurancePolicyNumber ,");
                    sb.Append("InsuranceDueDate ,");
                    sb.Append("InsuranceBillMailingAddress ,");
                    sb.Append("SoldDate ,");
                    sb.Append("amortization ,");
                    sb.Append("CurrentEstimateMarketValue ,");
                    sb.Append("ShareHoldPercentage )");
                    sb.Append(" values (");
                    if (model.PurchaseDate != DateTime.MinValue)
                    {
                        sb.Append("'" + model.PurchaseDate + "',");
                    }
                    else
                    {
                        sb.Append("null,");
                    }
                    sb.Append("'" + model.Address + "',");
                    sb.Append("'" + model.City + "',");
                    sb.Append("'" + model.Zip + "',");
                    sb.Append(model.PurchasePrice + ",");
                    sb.Append(model.PropertyTaxYearPayment + ",");
                    sb.Append("'" + model.PropertyTaxMailingAddress + "',");
                    if (model.PropertyTaxDueDate != DateTime.MinValue)
                    {
                        sb.Append("'" + model.PropertyTaxDueDate + "',");
                    }
                    else
                    {
                        sb.Append("null,");
                    }
                    sb.Append(model.StatusID + ",");
                    sb.Append("'" + model.note + "',");
                    sb.Append(model.InterestRate + ",");
                    sb.Append(model.LoanAmount + ",");
                    sb.Append("'" + model.InsuranceCompany + "',");
                    sb.Append(model.InsurancePremium + ",");
                    sb.Append("'" + model.InsurancePolicyNumber + "',");
                    if (model.InsuranceDueDate != DateTime.MinValue)
                    {
                        sb.Append("'" + model.InsuranceDueDate + "',");
                    }
                    else
                    {
                        sb.Append("null,");
                    }
                    sb.Append("'" + model.InsuranceBillMailingAddress + "',");
                    if (model.SoldDate != DateTime.MinValue)
                    {
                        sb.Append("'" + model.SoldDate + "',");
                    }
                    else
                    {
                        sb.Append("null,");
                    }
                    sb.Append(model.amortization + ",");
                    sb.Append(model.CurrentEstimateMarketValue + ",");
                    sb.Append(model.ShareHoldPercentage);
                    sb.Append(") SET @PropertyID=SCOPE_IDENTITY();");
                    cmd.CommandText = sb.ToString();
                    cmd.ExecuteNonQuery();
                    model.PropertyID = (int)IDParameter.Value;

                    //add Unit 0 by default
                    cmd.CommandText = "Insert into tblPropertyUnit (UnitName, PropertyID, Notes) values ('Unit 0', " + model.PropertyID + ", 'system auto generated')";
                    cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
                finally
                {
                    connection.Close();
                }
            }
            //insert company property
            InsertCompanyProperty(model.PropertyID, model.CompanyID, model.PurchaseDate);
        }