示例#1
0
        //ApplicationDbContext _context = new ApplicationDbContext();

        //post new shelter
        public IHttpActionResult Post(ShelterCreate shelter)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateShelterServices();

            if (!service.CreateShelter(shelter))
            {
                return(InternalServerError());
            }

            return(Ok($"Wonderful, {shelter.ShelterName} has been added to Bootz & Catz! ┌[ ◔ ͜ ʖ ◔ ]┐"));
        }
示例#2
0
        //private readonly Guid _userId;
        //public ShelterService(Guid userId)
        //{
        //    _userId = userId;
        //}
        public bool CreateShelter(ShelterCreate model)
        {
            var entity =
                new Shelter()
            {
                //OwnerId = _userId,
                ShelterName        = model.ShelterName,
                ShelterAddress     = model.ShelterAddress,
                ShelterPhoneNumber = model.ShelterPhoneNumber,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Shelters.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
        public ActionResult Create(ShelterCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            //var userId = Guid.Parse(User.Identity.GetUserId());
            var service = new ShelterService();

            if (service.CreateShelter(model))
            {
                TempData["SaveResult"] = "Your shelter was created.";
                return(RedirectToAction("Index"));
            }
            ;
            ModelState.AddModelError("", "Shelter could not be created.");
            return(View(model));
        }
示例#4
0
        //Shelter Create
        public bool CreateShelter(ShelterCreate model)
        {
            var entity =
                new Shelter()
            {
                //ShelterId = _shelterId,
                ShelterOwnerId = _userId,
                ShelterName    = model.ShelterName,
                ZipCode        = model.ZipCode,
                Description    = model.Description,
                PhoneNumber    = model.PhoneNumber,
                Address        = model.Address,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Shelters.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }