Пример #1
0
 public bool CreateOwner(OwnerCreate model)
 {
     using (var ctx = new ApplicationDbContext())
     {
         var newOwner = new Owner()
         {
             OwnerName = model.OwnerName
         };
         ctx.Owners.Add(newOwner);
         return(ctx.SaveChanges() == 1);
     }
 }
Пример #2
0
        public ActionResult Create(OwnerCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (new OwnerService().CreateOwner(model))
            {
                TempData["SaveResult"] = "Owner added";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Error adding an owner");
            return(View(model));
        }
Пример #3
0
        public IHttpActionResult Post(OwnerCreate ownerprofile)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateOwnerService();

            if (!service.CreateOwner(ownerprofile))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
Пример #4
0
        public bool CreateOwner(OwnerCreate model)
        {
            var entity =
                new Owner()
            {
                Id          = _Id,
                ProfileId   = model.ProfileId,
                ProfileName = model.ProfileName,
                Phone       = model.Phone,
                Email       = model.Email,
                Created     = DateTime.Now
            };

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