Example #1
0
        public bool CreateMaintRecord(MaintRecordCreate model)
        {
            var entity =
                new MaintRecord()
            {
                //OwnerId = _userId,
                ItemId     = model.ItemId,
                RecordText = model.RecordText,
                RecordDate = model.RecordDate
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.MaintRecords.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
        public ActionResult Create(MaintRecordCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new MaintRecordService(userId);

            if (service.CreateMaintRecord(model))
            {
                TempData["SaveResult"] = "Your note was created.";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "The record could not be created.");
            return(View(model));
        }