public async Task <ActionResult> DeleteConfirmed(int id)
        {
            OstvareniAchievementi ostvareniAchievementi = await db.OstvareniAchievementi.FindAsync(id);

            db.OstvareniAchievementi.Remove(ostvareniAchievementi);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            OstvareniAchievementi ostvareniAchievementi = await db.OstvareniAchievementi.FindAsync(id);

            if (ostvareniAchievementi == null)
            {
                return(HttpNotFound());
            }
            return(View(ostvareniAchievementi));
        }
        public async Task <ActionResult> Edit([Bind(Include = "UserID,AchievementID,AchivementOstvaren")]
                                              OstvareniAchievementi ostvareniAchievementi)
        {
            if (ModelState.IsValid)
            {
                db.Entry(ostvareniAchievementi).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.AchievementID = new SelectList(db.Achievements, "AchievementID", "Name",
                                                   ostvareniAchievementi.AchievementID);
            ViewBag.UserID = new SelectList(db.UserInfo, "UserID", "Username", ostvareniAchievementi.UserID);
            return(View(ostvareniAchievementi));
        }
        public ActionResult GenerirajAchievemente(bool?registracija)
        {
            var ostvareniAchievement = db.OstvareniAchievementi.ToList();
            var useri        = db.UserInfo.ToList();
            var achievementi = db.Achievements.ToList();
            var helpLista    = new List <OstvareniAchievementi>();

            foreach (var user in useri)
            {
                foreach (var achiev in achievementi)
                {
                    OstvareniAchievementi ostvaren = new OstvareniAchievementi {
                        UserID        = user.UserID,
                        AchievementID = achiev.AchievementID,
                    };
                    bool ima = false;
                    foreach (var ostAchiev in ostvareniAchievement)
                    {
                        if (mojEquals(ostvaren, ostAchiev))
                        {
                            ima = true;
                        }
                    }
                    if (!ima)
                    {
                        helpLista.Add(new OstvareniAchievementi
                        {
                            UserID             = user.UserID,
                            AchievementID      = achiev.AchievementID,
                            AchivementOstvaren = false
                        });
                    }
                }
            }
            db.OstvareniAchievementi.AddRange(helpLista);
            db.SaveChanges();
            if (registracija != null && registracija == true)
            {
                return(RedirectToAction("Index", "Home"));
            }
            return(RedirectToAction("Index", "Achievements"));
        }
        public ActionResult Edit(int?userID, int?achievementID)
        {
            if (userID == null || achievementID == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            List <OstvareniAchievementi> useroviAchievi =
                db.OstvareniAchievementi.Where(m => m.UserID == userID).ToList().Where(m => m.AchievementID == achievementID).ToList();

            if (useroviAchievi == null)
            {
                return(HttpNotFound());
            }
            OstvareniAchievementi pravaStvar = useroviAchievi.ElementAt(0);

            ViewBag.AchievementID = new SelectList(db.Achievements, "AchievementID", "Name",
                                                   pravaStvar.AchievementID);
            ViewBag.UserID = new SelectList(db.UserInfo, "UserID", "Username", pravaStvar.UserID);
            return(View(pravaStvar));
        }
 private bool mojEquals(OstvareniAchievementi generiran, OstvareniAchievementi baza)
 {
     return(generiran.AchievementID.Equals(baza.AchievementID) && generiran.UserID.Equals(baza.UserID));
 }