Beispiel #1
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            ApplicationDbContext db = new ApplicationDbContext();

            if (ModelState.IsValid)
            {
                int        idCondo  = Convert.ToInt32(Request.Form["condominio"]);
                CondoModel condoddl = db.CondoModels.FirstOrDefault(x => x.ID == idCondo);

                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, Condo_ID = idCondo
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        // GET: Condo/Create
        public ActionResult Create()
        {
            CondoModel model = new CondoModel();

            model.Address = new AddressModel();
            return(View(model));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            CondoModel condoModel = db.CondoModels.Find(id);

            db.CondoModels.Remove(condoModel);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CondoModel condoModel = db.CondoModels.Include(i => i.Address).FirstOrDefault(x => x.ID == id);

            if (condoModel == null)
            {
                return(HttpNotFound());
            }
            return(View(condoModel));
        }
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CondoModel condoModel = db.CondoModels.Find(id);

            if (condoModel == null)
            {
                return(HttpNotFound());
            }
            return(View(condoModel));
        }
        public ActionResult Create([Bind(Include = "ID,Name,ParkingSlots")] CondoModel condoModel)
        {
            if (ModelState.IsValid)
            {
                AddressModel address = new AddressModel();
                address.CEP          = Request.Form["CEP"];
                address.Street       = Request.Form["Street"];
                address.Number       = Request.Form["Number"];
                address.Neighborhood = Request.Form["Neighborhood"];
                address.City         = Request.Form["City"];
                address.State        = Request.Form["State"];

                db.AddressModels.Add(address);
                db.SaveChanges();

                condoModel.Address = address;

                db.CondoModels.Add(condoModel);
                db.SaveChanges();

                string   towers_units = Request.Form["towers_units"];
                string[] towers       = towers_units.Split(';');

                int nTowers = towers.Length;
                for (int t = 0; t < nTowers; t++)
                {
                    string[] units  = towers[t].Split(',');
                    int      nUnits = Convert.ToInt32(units[1]);

                    TowerModel tower = new TowerModel();
                    tower.Name     = String.Format(units[0]);
                    tower.UnitsQtd = nUnits;
                    tower.Condo    = condoModel;

                    db.TowerModels.Add(tower);
                    db.SaveChanges();
                }

                TempData["adm"] = "S";
                return(RedirectToAction("Create", "User", new { condo = condoModel.ID }));
            }

            return(View(condoModel));
        }
        public ActionResult Create(int?condo)
        {
            if (condo == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            CondoModel condoModel = db.CondoModels.Find(condo);

            if (condoModel == null)
            {
                return(HttpNotFound());
            }

            ViewBag.TowerId = new SelectList(db.TowerModels.Include(c => c.Condo).Where(x => x.Condo.ID == condo).ToList(), "Id", "Name");
            ViewBag.CondoId = condo;

            return(View());
        }
        public ActionResult Edit([Bind(Include = "ID,Name,ParkingSlots,Address")] CondoModel condoModel)
        {
            if (ModelState.IsValid)
            {
                db.Entry(condoModel).State = EntityState.Modified;
                db.SaveChanges();

                var condo = db.CondoModels.Include(i => i.Address).FirstOrDefault(x => x.ID == condoModel.ID);
                condo.Address.CEP          = Request.Form["CEP"];
                condo.Address.Street       = Request.Form["Street"];
                condo.Address.Number       = Request.Form["Number"];
                condo.Address.Neighborhood = Request.Form["Neighborhood"];
                condo.Address.City         = Request.Form["City"];
                condo.Address.State        = Request.Form["State"];

                db.Entry(condo.Address).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(View(condoModel));
        }
        public ActionResult Create([Bind(Include = "ID,CompanyName,Tel,CNPJ,Site,Contact")] OutSourcerModel outSourcerModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    AddressModel address = new AddressModel();
                    address.CEP          = Request.Form["CEP"];
                    address.Street       = Request.Form["Street"];
                    address.Number       = Request.Form["Number"];
                    address.Neighborhood = Request.Form["Neighborhood"];
                    address.City         = Request.Form["City"];
                    address.State        = Request.Form["State"];

                    db.AddressModels.Add(address);
                    db.SaveChanges();

                    outSourcerModel.Address = address;

                    var        user  = db.Users.Find(User.Identity.GetUserId());
                    CondoModel condo = db.CondoModels.Find(user.Condo_ID);

                    outSourcerModel.Condo = condo;

                    db.OutSourcerModels.Add(outSourcerModel);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }catch
                {
                    ModelState.AddModelError("ErrorOutSourcer", "Ocorreu um erro ao salvar o prestador.");
                    return(View(outSourcerModel));
                }
            }

            return(View(outSourcerModel));
        }