public ActionResult Create(HomeCreateModel inmodel)
        {
            var model = new HomeCreateModel();

            using (var db = new TicketsDbModel())
            {
                if (inmodel.Ticket != null)
                {
                    inmodel.Ticket.Id = 0;
                    inmodel.Ticket.DateTimeCreated  = DateTime.Now;
                    inmodel.Ticket.CreatedByUser    = db.Users.Where(u => u.Username == User.Identity.Name).FirstOrDefault();
                    inmodel.Ticket.DateTimeModified = inmodel.Ticket.DateTimeCreated;
                    inmodel.Ticket.ModifiedByUser   = inmodel.Ticket.CreatedByUser;
                    model.Ticket = inmodel.Ticket;
                }

                if (ModelState.IsValid)
                {
                    db.Entry(inmodel.Ticket).State = System.Data.Entity.EntityState.Added;
                    db.SaveChanges();
                }
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            else
            {
                return(RedirectToAction("Edit", new { id = model.Ticket.Id }));
            }
        }
Exemplo n.º 2
0
 public IActionResult Create([FromBody] HomeCreateModel model)
 {
     if (model.Fk_Role == (int)Role.admin || model.Fk_Role != (int)Role.moderator)
     {
         return(BadRequest(new
         {
             message = "У вас нет прав на выолнение данного запроса!"
         }));
     }
     try
     {
         var home = (Home)model;
         db.Home.Add(home);
         db.SaveChanges();
         var user = db.User.FirstOrDefault(x => x.Uid == model.Manager);
         user.Fk_Home        = home.Uid;
         user.IsApprovedHome = true;
         user.Address        = "г. " + model.City + ", " + model.Street + ", д. " + model.HomeNumber;
         db.User.Update(user);
         db.SaveChanges();
         return(Ok(home));
     }
     catch (Exception)
     {
         return(BadRequest(new
         {
             message = "На сервере произошла ошибка, попробуйте позже"
         }));
     }
 }
        public ActionResult Create()
        {
            var model = new HomeCreateModel();

            return(View(model));
        }