Example #1
0
        public ActionResult Create(YearlyMembership yearlymembership)
        {
            if (ModelState.IsValid)
            {
                db.Memmberships.Add(yearlymembership);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }


            List <object> listagodina = new List <object>();

            foreach (var p in db.Years)
            {
                listagodina.Add(
                    new
                {
                    Id   = p.ID,
                    Name = p.BeginDate.Year
                }

                    );
            }

            ViewBag.UserId = new SelectList(db.Users, "ID", "Name", yearlymembership.UserId);
            ViewBag.YearId = new SelectList(listagodina, "ID", "Name", yearlymembership.YearId);
            return(View(yearlymembership));
        }
Example #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            YearlyMembership yearlymembership = db.Memmberships.Find(id);

            db.Memmberships.Remove(yearlymembership);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #3
0
 public ActionResult Edit([Bind(Include = "ID,Amount,UserId,YearId")] YearlyMembership yearlymembership)
 {
     if (ModelState.IsValid)
     {
         db.Entry(yearlymembership).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.UserId = new SelectList(db.Users, "ID", "Name", yearlymembership.UserId);
     ViewBag.YearId = new SelectList(db.Years, "ID", "ID", yearlymembership.YearId);
     return(View(yearlymembership));
 }
Example #4
0
        // GET: /Clanarine/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            YearlyMembership yearlymembership = db.Memmberships.Find(id);

            if (yearlymembership == null)
            {
                return(HttpNotFound());
            }
            return(View(yearlymembership));
        }
Example #5
0
        // GET: /Clanarine/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            YearlyMembership yearlymembership = db.Memmberships.Find(id);

            if (yearlymembership == null)
            {
                return(HttpNotFound());
            }
            ViewBag.UserId = new SelectList(db.Users, "ID", "Name", yearlymembership.UserId);
            ViewBag.YearId = new SelectList(db.Years, "ID", "ID", yearlymembership.YearId);
            return(View(yearlymembership));
        }
Example #6
0
        //INSERTS



        public YearlyMembership InsertMembership(Uplata uplata)
        {
            YearlyMembership membership  = new YearlyMembership();
            User             user        = db.Users.Find(uplata.UserId);
            Year             year        = db.Years.Find(uplata.YearId);
            VrstaUplate      vrstaUplate = db.VrsteUplata.Find(uplata.VrstaId);

            //inicijaliziraj membership
            membership.User          = user;
            membership.Year          = year;
            membership.VrstaUplate   = vrstaUplate;
            membership.Amount        = uplata.Amount;
            membership.UserId        = uplata.UserId;
            membership.YearId        = uplata.YearId;
            membership.VrstaUplateID = uplata.VrstaId;
            membership.DatumUplate   = uplata.Datum;


            try
            {
                db.Memmberships.Add(membership);

                //smanji dug


                var dug = db.Dugovi.Where(p => p.UserID == uplata.UserId && p.YearID == uplata.YearId).FirstOrDefault();
                dug.Amount -= uplata.Amount;

                db.Entry(dug).State = System.Data.Entity.EntityState.Modified;

                return(membership);
            }

            catch
            {
                return(null);
            }
        }