Exemple #1
0
 public ActionResult Edit([Bind(Include = "Id,Content,UserId,BookId,IsDeleted,DeletedOn,CreatedOn,ModifiedOn")] Comment comment)
 {
     if (ModelState.IsValid)
     {
         comments.Update(comment);
         context.Commit();
         return(RedirectToAction("Index"));
     }
     ViewBag.BookId = new SelectList(books.All(), "Id", "Title", comment.BookId);
     ViewBag.UserId = new SelectList(users.All(), "Id", "FirstName", comment.UserId);
     return(View(comment));
 }
Exemple #2
0
        public ActionResult Create([Bind(Include = "Id,Name,IsDeleted,DeletedOn,CreatedOn,ModifiedOn")] Category category)
        {
            if (ModelState.IsValid)
            {
                category.Id        = Guid.NewGuid();
                category.CreatedOn = DateTime.Now;
                categories.Add(category);
                context.Commit();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
Exemple #3
0
        public Guid Create(OrderItem orderItem)
        {
            this.orderItemsRepo.Add(orderItem);
            context.Commit();

            return(orderItem.Id);
        }
Exemple #4
0
        public void ChangeTableStatus(Table table)
        {
            if (table == null)
            {
                throw new NullReferenceException();
            }

            table.IsFree = !table.IsFree;
            this.tableRepository.Update(table);

            saveContext.Commit();
        }
Exemple #5
0
        public void AddMessageToGroup(string groupName, string messageAuthor, string messageContent)
        {
            var group = this.groups.All()
                        .SingleOrDefault(g => g.Name == groupName && !g.IsDeleted);

            if (group != null)
            {
                var message = new Message(messageAuthor, messageContent);

                message.CreatedOn = DateTime.Now;
                message.Group     = group;
                message.GroupId   = group.Id;

                group.Messages.Add(message);

                saveContext.Commit();
            }
        }
        public async Task<ActionResult> AddAdmin(RegisterAdminViewModel model)
        {
            School school = schoolRepository.GetById(model.SchoolId);

            if (ModelState.IsValid)
            {
                if (!RoleManager.RoleExists(WebRoles.Admin))
                {
                    RoleManager.Create(new IdentityRole(WebRoles.Admin));
                }

                var user = new User() { UserName = model.Email, Email = model.Email };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    // Add user in Admin role
                    UserManager.AddToRole(user.Id, WebRoles.Admin);

                    // Add user id to school
                    school.AdminId = user.Id;
                    schoolRepository.Update(school);
                    saveContext.Commit();

                    return RedirectToAction("Index/" + model.SchoolId, new { area = "Admin"});
                }
                AddErrors(result);
            }

            ViewBag.Breadcrumb = new List<Breadcrumb>()
            {
                new Breadcrumb(Breadcrumb.HomeName, Breadcrumb.AdminHomeUrl),
                new Breadcrumb(school.Name, Breadcrumb.AdminSchoolUrl + "/index/" + model.SchoolId),
                new Breadcrumb(Breadcrumb.ActionAdd)
            };

            return View(model);
        }