Beispiel #1
0
        public ActionResult New([Bind(Include = "headerText,description")] TicketViewModel tvm)
        //"ID,originatorUsername,dateComposed,headerText,description,dateSubmitted,adminEmail,dateL1Release,dateL2Release,sanityCheck")] Ticket ticket)
        {
            if (ModelState.IsValid)
            {
                UserData    ud          = new UserData();
                UserProfile userProfile = ud.getUserProfile();

                Ticket ticket = new Ticket();
                ticket.headerText  = tvm.headerText;
                ticket.description = tvm.description;

                ticket.dateComposed = DateTime.Now;
                ticket.originatorID = userProfile.userID;

                /*ticket.dateL1Release =
                 * ticket.dateL2Release = null;
                 * ticket.dateSubmitted = null;
                 */
                db.Tickets.Add(ticket);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tvm));
        }
        // POST: Artigo/Votar/5
        public ActionResult Votar(String voto, int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Artigo artigo = db.Artigos.Find(id);

            if (artigo == null)
            {
                return(HttpNotFound());
            }

            if (ModelState.IsValid)
            {
                if (voto == "true")
                {
                    artigo.QtdLike++;
                }
                if (voto == "false")
                {
                    artigo.QtdUnlike++;
                }

                db.Entry(artigo).State = EntityState.Modified;
                db.SaveChanges();
                return(View("Detalhes", artigo));
            }
            return(View("Detalhes", artigo));
        }
        public ActionResult Index([Bind(Include = "ID,AdminEmail,TicketSeeder,FAQApprover,KBApprover,TicketHeader,Keyowrds,ExpertArea,TicketExpiry")] GlobalSettings globalSettings)
        {
            if (ModelState.IsValid)
            {
                //GlobalSettings globalSettings = gsm.getSettings();


                if (globalSettings.ID == Guid.Empty || globalSettings.ID == null)
                {
                    globalSettings.ID = Guid.NewGuid();
                    db.GlobalSettingss.Add(globalSettings);
                }
                else
                {
                    db.Entry(globalSettings).State = EntityState.Modified;
                }
                db.SaveChanges();

                ViewBag.Msg = "Changes saved";
                return(RedirectToAction("Index"));
            }
            else
            {
                ViewBag.Msg = "Model not valid";
            }

            GlobalSettingsEditModel gsm = new GlobalSettingsEditModel(globalSettings);

            return(View(gsm));
        }
        public ActionResult Indexn([Bind(Include = "userID,loginName,principalName,firstName,surName,emailAddress,contactNumber")] UserProfile userProfile)
        {
            if (ModelState.IsValid)
            {
                userProfile.userID = Guid.NewGuid();
                db.UserProfiles.Add(userProfile);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(userProfile));
        }
        public ActionResult Create([Bind(Include = "Id,Name,Date,Camera,Price,Image,ProducerId,BatteryId,ColorId")] Mobile mobile)
        {
            if (ModelState.IsValid)
            {
                db.Mobiles.Add(mobile);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.BatteryId  = new SelectList(db.Batterys, "Id", "Id", mobile.BatteryId);
            ViewBag.ColorId    = new SelectList(db.Colors, "Id", "Name", mobile.ColorId);
            ViewBag.ProducerId = new SelectList(db.Producers, "Id", "Name", mobile.ProducerId);
            return(View(mobile));
        }
        public ActionResult Edit(User user)
        {
            if (ModelState.IsValid)
            {
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            SelectList roles = new SelectList(db.Roles, "id", "Name");

            ViewBag.Roles = roles;

            return(View(user));
        }
Beispiel #7
0
        public ActionResult Create([Bind(Include = "ID,text,type")] WordListViewModel wlm)
        {
            WordList wordList = new WordList();

            wordList.text = wlm.text;
            wordList.type = 1;

            if (ModelState.IsValid)
            {
                db.WordLists.Add(wordList);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(wlm));
        }
        public ActionResult Abrir([Bind(Include = "Titulo,TopicoID,SubtopicoID")] Chamado chamado, String conteudoForm)
        {
            if (ModelState.IsValid)
            {
                Usuario usuario = db.Usuarios.Find(Session["userLoggedId"]);
                chamado.UsuarioID = usuario.Id;

                chamado.Status      = EnumStatus.AguardandoResposta;
                chamado.DataCriacao = DateTime.Now;

                var listaSubtSuporte = db.Subtopicos.Where(st => st.TopicoID == 1).ToList();
                var listaSubtDev     = db.Subtopicos.Where(st => st.TopicoID == 2).ToList();

                if (listaSubtSuporte.Any(st => st.Id == chamado.SubtopicoID))
                {
                    chamado.EquipeAtendimento = EnumTipoEquipe.Suporte;
                }
                else if (listaSubtDev.Any(st => st.Id == chamado.SubtopicoID))
                {
                    chamado.EquipeAtendimento = EnumTipoEquipe.Desenvolvimento;
                }
                else
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                // Cria uma instância de 'Conteudo' para salvar na lista de 'Conteudos' do chamado
                Conteudo conteudoSalvar = new Conteudo();
                conteudoSalvar.ConteudoChamado = conteudoForm;
                conteudoSalvar.UsuarioID       = usuario.Id;
                conteudoSalvar.DataCriacao     = DateTime.Now;
                conteudoSalvar.ChamadoID       = chamado.Id;           // salva o chamado no 'conteudo'
                db.Conteudos.Add(conteudoSalvar);

                chamado.Conteudos.Add(conteudoSalvar);                 // salva o conteudo no chamado
                db.Chamados.Add(chamado);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.TopicoID    = new SelectList(db.Topicos, "Id", "Titulo");
            ViewBag.SubtopicoID = new SelectList(db.Subtopicos, "Id", "Titulo");
            return(View(chamado));
        }
Beispiel #9
0
        public static void CreateTicketUserAssociation(int userId, int ticketId, HelpDeskContext _context)
        {
            // Create association with user
            UserTickets userTicket = new UserTickets()
            {
                UserId   = userId,
                TicketId = ticketId
            };

            // Add association to database
            _context.UserTickets.Add(userTicket);
            _context.SaveChanges();
        }
Beispiel #10
0
 private bool CreateUser(string login, string password, string salt)
 {
     using (HelpDeskContext db = new HelpDeskContext())
     {
         try
         {
             db.Users.Add(new User {
                 Login = login, Password = password, RoleId = 2, Salt = salt
             });
             db.SaveChanges();
         }
         catch
         {
             return(false);
         }
     }
     return(true);
 }
Beispiel #11
0
 public void Add(TEndity obj)
 {
     Db.Set <TEndity>().Add(obj);
     Db.SaveChanges();
 }
 public void SaveChanges()
 {
     db.SaveChanges();
 }
        public UserProfile getUserProfile()
        {
            if (userProfile != null)
            {
                return(userProfile);
            }
            bool isLoggedIn = (HttpContext.Current.User != null && HttpContext.Current.User.Identity.IsAuthenticated);

            if (isLoggedIn)
            {
                var    user      = HttpContext.Current.User;
                string loginName = user.Identity.Name;

                PrincipalContext ctx;

                if (loginName.IndexOf(@"\") > 0)
                {
                    ctx = new PrincipalContext(ContextType.Domain, loginName.Substring(0, loginName.IndexOf(@"\")));
                }
                else
                {
                    ctx = new PrincipalContext(ContextType.Domain);
                }

                var userPrincipal = UserPrincipal.FindByIdentity(ctx, loginName);

                try
                {
                    if (user != null)
                    {
                        HelpDeskContext db = new HelpDeskContext();

                        //Grab current user from profile
                        userProfile = db.UserProfiles.Find(userPrincipal.Guid);

                        if (userProfile == null) // If user has no profile add it
                        {
                            //Add profile to database then populate userProfile object from database
                            userProfile = new UserProfile
                            {
                                userID        = (Guid)userPrincipal.Guid,
                                firstName     = userPrincipal.GivenName,
                                loginName     = loginName,
                                principalName = userPrincipal.UserPrincipalName,
                                surName       = userPrincipal.Surname,
                                // not using d ud.displayName,
                            };
                            db.UserProfiles.Add(userProfile);
                            db.SaveChanges();
                            userProfile = db.UserProfiles.Find(userPrincipal.Guid);
                        }
                    }
                }
                catch (Exception ex)
                {
                    //if (Globals.debug) Globals.form1Err += "Part2 Error: " + ex.Message;
                    errorMsg              = ex.Message;
                    userProfile           = new UserProfile();
                    userProfile.firstName = "";
                    userProfile.surName   = "Anonymous";
                }
            }
            else
            {
                userProfile           = new UserProfile();
                userProfile.firstName = "";
                userProfile.surName   = "Anonymous";
            }

            return(userProfile);
        }
Beispiel #14
0
        public UserProfile getUserProfile()
        {
            UserProfile userProfile = null;

            if (HttpContext.Current.Session["UserID"] == null)
            {
                bool isLoggedIn = (HttpContext.Current.User != null && HttpContext.Current.User.Identity.IsAuthenticated);
                if (isLoggedIn)
                {
                    var    user      = HttpContext.Current.User;
                    string loginName = user.Identity.Name;

                    PrincipalContext ctx;

                    if (loginName.IndexOf(@"\") > 0)
                    {
                        ctx = new PrincipalContext(ContextType.Domain, loginName.Substring(0, loginName.IndexOf(@"\")));
                    }

                    else
                    {
                        ctx = new PrincipalContext(ContextType.Domain);
                    }

                    var userPrincipal = UserPrincipal.FindByIdentity(ctx, loginName);

                    try
                    {
                        if (user != null)
                        {
                            HelpDeskContext db = new HelpDeskContext();

                            //Grab current user from profile
                            userProfile = db.UserProfiles.Find(userPrincipal.Guid);

                            if (userProfile == null) // If user has no profile add it
                            {
                                //Add profile to database then populate userProfile object from database
                                userProfile = new UserProfile
                                {
                                    userID        = (Guid)userPrincipal.Guid,
                                    firstName     = userPrincipal.GivenName,
                                    loginName     = loginName,
                                    principalName = userPrincipal.UserPrincipalName,
                                    surName       = userPrincipal.Surname,
                                    // not using d ud.displayName,
                                };
                                db.UserProfiles.Add(userProfile);
                                db.SaveChanges();
                                userProfile = db.UserProfiles.Find(userPrincipal.Guid);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        //if (Globals.debug) Globals.form1Err += "Part2 Error: " + ex.Message;

                        userProfile           = new UserProfile();
                        userProfile.firstName = "";
                        userProfile.surName   = "Anonymous";
                    }

                    if (userProfile != null && userProfile.userID != Guid.Empty)
                    {
                        HttpContext.Current.Session.Add("UserID", userProfile.userID);
                    }
                }
                else
                {
                    userProfile           = new UserProfile();
                    userProfile.firstName = "";
                    userProfile.surName   = "Anonymous";
                }

                return(userProfile);
            }
            else
            {
                return(db.UserProfiles.Find((Guid)HttpContext.Current.Session["UserID"]));
            }


            /*
             * if (userProfile != null )
             * {
             *  return userProfile;
             * }
             * bool isLoggedIn = (HttpContext.Current.User != null && HttpContext.Current.User.Identity.IsAuthenticated);
             * if (isLoggedIn)
             * {
             *  var user = HttpContext.Current.User;
             *  string loginName = user.Identity.Name;
             *
             *  PrincipalContext ctx;
             *
             *  if (loginName.IndexOf(@"\") > 0)
             *  {
             *      ctx = new PrincipalContext(ContextType.Domain, loginName.Substring(0, loginName.IndexOf(@"\")));
             *  }
             *
             *  else
             *  {+
             *      ctx = new PrincipalContext(ContextType.Domain);
             *  }
             *
             *  var userPrincipal = UserPrincipal.FindByIdentity(ctx, loginName);
             *
             *  try
             *  {
             *      if (user != null)
             *      {
             *          HelpDeskContext db = new HelpDeskContext();
             *
             *          //Grab current user from profile
             *          userProfile = db.UserProfiles.Find(userPrincipal.Guid);
             *
             *          if (userProfile == null) // If user has no profile add it
             *          {
             *              //Add profile to database then populate userProfile object from database
             *              userProfile = new UserProfile
             *              {
             *                  userID = (Guid)userPrincipal.Guid,
             *                  firstName = userPrincipal.GivenName,
             *                  loginName = loginName,
             *                  principalName = userPrincipal.UserPrincipalName,
             *                  surName = userPrincipal.Surname,
             *                  // not using d ud.displayName,
             *
             *              };
             *              db.UserProfiles.Add(userProfile);
             *              db.SaveChanges();
             *              userProfile = db.UserProfiles.Find(userPrincipal.Guid);
             *          }
             *
             *      }
             *  }
             *  catch (Exception ex)
             *  {
             *      //if (Globals.debug) Globals.form1Err += "Part2 Error: " + ex.Message;
             *      errorMsg = ex.Message;
             *      userProfile = new UserProfile();
             *      userProfile.firstName = "";
             *      userProfile.surName = "Anonymous";
             *  }
             *
             * } else {
             *  userProfile = new UserProfile();
             *  userProfile.firstName = "";
             *  userProfile.surName = "Anonymous";
             * }
             *
             * return userProfile;
             */
        }