예제 #1
0
        public async Task <JsonResult> GetBasketTotalCountAndPrice()
        {
            using (Models.AppContext context = Models.AppContext.Create())
            {
                int totalPrice = 0;
                int totalCount = 0;

                var user = await context.Users.Include(x => x.UserBasket).Where(y => y.UserName == this.User.Identity.Name).FirstOrDefaultAsync();

                if (user != null)
                {
                    context.Entry(user.UserBasket).Collection("BasketItems").Load();

                    foreach (BasketItem item in user.UserBasket.BasketItems)
                    {
                        context.Entry(item).Reference("HairItem").Load();
                        totalPrice += item.HairItem.Price * item.Quality;
                        totalCount += item.Quality;
                    }
                }

                Dictionary <string, string> data = new Dictionary <string, string>(2);
                data.Add("price", totalPrice.ToString());
                data.Add("count", totalCount.ToString());

                return(Json(data, JsonRequestBehavior.AllowGet));
            }
        }
예제 #2
0
        public JsonResult AddBasketItem(int itemId)
        {
            using (Models.AppContext context = Models.AppContext.Create())
            {
                var user = context.Users.Where(x => x.UserName == this.User.Identity.Name).FirstOrDefault();
                var item = context.HairItems.Find(itemId);
                if (user != null && item != null)
                {
                    context.Entry(user).Reference("UserBasket").Load();
                    context.Entry(user.UserBasket).Collection("BasketItems").Load();

                    foreach (BasketItem tempItem in user.UserBasket.BasketItems)
                    {
                        context.Entry(tempItem).Reference("HairItem").Load();
                        if (tempItem.HairItem.Id == itemId)
                        {
                            tempItem.Quality += 1;
                            context.SaveChanges();
                            return(Json(true));
                        }
                    }

                    BasketItem basketItem = new BasketItem {
                        HairItem = item, Quality = 1, UserBasket = user.UserBasket
                    };
                    context.BasketItems.Add(basketItem);
                    context.SaveChanges();
                    return(Json(true));
                }
                return(Json(false));
            }
        }
예제 #3
0
        public async Task <ActionResult> GetBasket()
        {
            using (Models.AppContext context = Models.AppContext.Create())
            {
                var user = await context.Users.Include(x => x.UserBasket).Where(y => y.UserName == this.User.Identity.Name).FirstOrDefaultAsync();

                if (user != null)
                {
                    context.Entry(user.UserBasket).Collection("BasketItems").Load();
                    foreach (BasketItem item in user.UserBasket.BasketItems)
                    {
                        context.Entry(item).Reference("HairItem").Load();
                    }

                    if (user.UserBasket.BasketItems.Count <= 0)
                    {
                        return(PartialView("GetEmptyBasket"));
                    }
                    return(PartialView(user.UserBasket));
                }
                else
                {
                    return(null);
                }
            }
        }
예제 #4
0
        public async Task <IHttpActionResult> PutOrder(int id, Order order)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != order.Id)
            {
                return(BadRequest());
            }

            db.Entry(order).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrderExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #5
0
        public async Task <IActionResult> PutLabel([FromRoute] int id, [FromBody] Label label)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != label.Id)
            {
                return(BadRequest());
            }

            label.LaatstGewijzigd       = DateTime.Now;
            _context.Entry(label).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LabelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutProduct([FromRoute] int id, [FromBody] Product product)
        {
            if (id != product.Id)
            {
                return(BadRequest());
            }

            _context.Entry(product).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (_context.Products.Find(id) == null)
                {
                    return(NotFound());
                }

                throw;
            }

            return(NoContent());
        }
예제 #7
0
        public async Task <IActionResult> PutStorage(int id, Storage storage)
        {
            if (id != storage.Id)
            {
                return(BadRequest());
            }

            _context.Entry(storage).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StorageExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #8
0
 public IHttpActionResult Put(Pessoa pessoa)
 {
     if (!ModelState.IsValid || pessoa == null)
     {
         return(BadRequest("Dados do contato inválidos"));
     }
     using (var ctx = new Models.AppContext())
     {
         var contatoSelecionado = ctx.Pessoas.Where(p => p.Id == pessoa.Id).FirstOrDefault <Pessoa>();
         if (contatoSelecionado != null)
         {
             contatoSelecionado.Name             = pessoa.Name;
             contatoSelecionado.Email            = pessoa.Email;
             contatoSelecionado.Username         = pessoa.Username;
             contatoSelecionado.Password         = pessoa.Password;
             ctx.Entry(contatoSelecionado).State = EntityState.Modified;
             ctx.SaveChanges();
         }
         else
         {
             return(NotFound());
         }
     }
     return(Ok($"{pessoa.Name} atualizado com sucesso"));
 }
예제 #9
0
        public IActionResult OnGet(string id)
        {
            string userEmail = this.HttpContext.User.Identity.Name;

            if (string.IsNullOrEmpty(userEmail))
            {
                return(Redirect("~/login"));
            }
            else
            {
                this.CurrentUser = context.Set <Models.User>().Where(entry => entry.Email.Equals(userEmail)).FirstOrDefault();
                context.Entry(this.CurrentUser).Collection(u => u.Templates).Load();

                Template template = this.context.Set <Template>().Where(temp => temp.ID.Equals(new Guid(id))).FirstOrDefault();
                if (template == null || !this.CurrentUser.Templates.Any(t => t.ID.Equals(template.ID)))
                {
                    return(Redirect("/templates"));
                }


                this.Template = template;
                Breadcrumb.AddLast(Tuple.Create <string, string>(template.Title, null));
            }

            return(Page());
        }
 public virtual void Update(T entity)
 {
     using (var context = new Models.AppContext())
     {
         context.Entry(entity).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #11
0
 public ActionResult Edit([Bind(Include = "Id,TownName,Color")] HomeList homeList)
 {
     if (ModelState.IsValid)
     {
         db.Entry(homeList).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(homeList));
 }
예제 #12
0
 public ActionResult Edit([Bind(Include = "Id,Brand,TypeOfEngine")] CarList carList)
 {
     if (ModelState.IsValid)
     {
         db.Entry(carList).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(carList));
 }
예제 #13
0
        public void Delete(int id)
        {
            var item = context.HairItems.Find(id);

            if (item != null)
            {
                context.Entry(item).State = EntityState.Deleted;
                context.SaveChanges();
            }
        }
예제 #14
0
 public ActionResult Edit([Bind(Include = "Id,Title,Detail,Done")] Todo todo)
 {
     if (ModelState.IsValid)
     {
         db.Entry(todo).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(todo));
 }
예제 #15
0
 public ActionResult Edit([Bind(Include = "Id,UserName,Password")] User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(user));
 }
예제 #16
0
 public ActionResult Edit([Bind(Include = "ID,Message,Created")] Soliloquy soliloquy)
 {
     if (ModelState.IsValid)
     {
         db.Entry(soliloquy).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(soliloquy));
 }
예제 #17
0
        public async Task <IActionResult> PutTransactie([FromRoute] int id, [FromBody] TransactiePostModel transactiePM)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != transactiePM.Id)
            {
                return(BadRequest());
            }

            Transactie transactie = _context.Transactie.Where(a => a.Id == id).Include(a => a.TransactieLabels).First();

            transactie.LaatstGewijzigd = DateTime.Now;
            transactie.Bedrag          = transactiePM.Bedrag;
            transactie.Datum           = transactiePM.Datum;
            transactie.Omschrijving    = transactiePM.Omschrijving;
            transactie.Type            = transactiePM.Type;
            transactie.Document        = transactiePM.Document;
            transactie.DocumentNaam    = transactiePM.DocumentNaam;
            transactie.VanRekening     = transactiePM.VanRekening;
            transactie.NaarRekening    = transactiePM.NaarRekening;

            transactie.TransactieLabels.Clear();

            foreach (var newLabelId in transactiePM.Label)
            {
                Label label = _context.Label.Where(l => l.Id == newLabelId).First();
                transactie.TransactieLabels.Add
                (
                    nieuwTransactieLabel(transactie, label)
                );
            }

            _context.Entry(transactie).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TransactieExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #18
0
        public ActionResult OnGet()
        {
            string userEmail = this.HttpContext.User.Identity.Name;

            if (string.IsNullOrEmpty(userEmail))
            {
                return(Redirect("~/login"));
            }
            else
            {
                // TODO does cookie have data integrity?
                this.CurrentUser = this.GetUser(HttpContext.User.Identity.Name);
                _context.Entry(this.CurrentUser).Collection(u => u.CertDetails).Load();
                _context.Entry(this.CurrentUser).Collection(u => u.SkillDetails).Load();
                _context.Entry(this.CurrentUser).Collection(u => u.WorkDetails).Load();
                _context.Entry(this.CurrentUser).Collection(u => u.ProjectDetails).Load();
                _context.Entry(this.CurrentUser).Collection(u => u.EducationDetails).Load();
                return(Page());
            }
        }
예제 #19
0
        public async Task <IActionResult> PutLening([FromRoute] int id, [FromBody] LeningPostModel leningPM)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != leningPM.Id)
            {
                return(BadRequest());
            }

            Lening lening = _context.Lening.Where(a => a.Id == id).Include(a => a.LeningLabels).First();

            lening.LaatstGewijzigd = DateTime.Now;
            lening.Bedrag          = leningPM.Bedrag;
            lening.Begindatum      = leningPM.Begindatum;
            lening.Looptijd        = leningPM.Looptijd;
            lening.Type            = leningPM.Type;
            lening.Rente           = leningPM.Rente / 100;
            lening.Document        = leningPM.Document;
            lening.DocumentNaam    = leningPM.DocumentNaam;

            lening.LeningLabels.Clear();

            foreach (var newLabelId in leningPM.Label)
            {
                Label label = _context.Label.Where(l => l.Id == newLabelId).First();
                lening.LeningLabels.Add
                (
                    nieuwLeningLabel(lening, label)
                );
            }

            _context.Entry(lening).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LeningExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public ActionResult OnGet()
        {
            this.Breadcrumb = new LinkedList <Tuple <string, string> >();
            Breadcrumb.AddLast(Tuple.Create <string, string>("Home", "/home"));
            Breadcrumb.AddLast(Tuple.Create <string, string>("Favourites", null));

            // TODO can this email be spoofed?
            string userEmail = this.HttpContext.User.Identity.Name;

            if (string.IsNullOrEmpty(userEmail))
            {
                return(Redirect("~/login"));
            }
            else
            {
                this.CurrentUser = _context.Set <User>().Where(entry => entry.Email.Equals(userEmail)).FirstOrDefault();
                _context.Entry(this.CurrentUser).Collection(u => u.Favorites).Load();
                return(Page());
            }
        }
        public async Task <ActionResult> Edit([Bind(Include = "Id,OrderNo,CustemerId,PMethod,GTotal")] Order order)
        {
            if (ModelState.IsValid)
            {
                db.Entry(order).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(order));
        }
예제 #22
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,Name,Price")] Item item)
        {
            if (ModelState.IsValid)
            {
                db.Entry(item).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(item));
        }
예제 #23
0
        public async Task <IActionResult> PutAfschrijving([FromRoute] int id, [FromBody] AfschrijvingPostModel afschrijvingPM)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != afschrijvingPM.Id)
            {
                return(BadRequest());
            }

            Afschrijving afschrijving = _context.Afschrijving.Where(a => a.Id == id).Include(a => a.AfschrijvingLabels).First();

            afschrijving.LaatstGewijzigd     = DateTime.Now;
            afschrijving.Aankoopbedrag       = afschrijvingPM.Aankoopbedrag;
            afschrijving.Aankoopdatum        = afschrijvingPM.Aankoopdatum;
            afschrijving.VerwachteLevensduur = afschrijvingPM.VerwachteLevensduur;
            afschrijving.Garantie            = afschrijvingPM.Garantie;
            afschrijving.Factuur             = afschrijvingPM.Factuur;
            afschrijving.FactuurNaam         = afschrijvingPM.FactuurNaam;

            afschrijving.AfschrijvingLabels.Clear();

            foreach (var newLabelId in afschrijvingPM.Label)
            {
                Label label = _context.Label.Where(l => l.Id == newLabelId).First();
                afschrijving.AfschrijvingLabels.Add
                (
                    nieuwAfschrijvingLabel(afschrijving, label)
                );
            }

            _context.Entry(afschrijving).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AfschrijvingExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
 public virtual void Delete(T entity)
 {
     using (var context = new Models.AppContext())
     {
         if (context.Entry(entity).State == EntityState.Detached)
         {
             context.Set <T>().Attach(entity);
         }
         context.Set <T>().Remove(entity);
         context.SaveChanges();
     }
 }
예제 #25
0
        public async Task <IActionResult> PutContract([FromRoute] int id, [FromBody] ContractPostModel contractPM)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != contractPM.Id)
            {
                return(BadRequest());
            }

            Contract contract = _context.Contract.Where(i => i.Id == id).Include(i => i.ContractLabels).First();

            contract.Bedrag          = contractPM.Bedrag;
            contract.Begindatum      = contractPM.Begindatum;
            contract.Einddatum       = contractPM.Einddatum;
            contract.Interval        = contractPM.Interval;
            contract.Document        = contractPM.Document;
            contract.DocumentNaam    = contractPM.DocumentNaam;
            contract.LaatstGewijzigd = DateTime.Now;

            contract.ContractLabels.Clear();

            foreach (var newLabelId in contractPM.Label)
            {
                Label label = _context.Label.Where(l => l.Id == newLabelId).First();
                contract.ContractLabels.Add
                (
                    nieuwContractLabel(contract, label)
                );
            }

            _context.Entry(contract).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ContractExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #26
0
        public async Task <IActionResult> PutInkomst([FromRoute] int id, [FromBody] InkomstPostModel inkomstVM)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != inkomstVM.Id)
            {
                return(BadRequest());
            }

            Inkomst inkomst = _context.Inkomst.Where(i => i.Id == id).Include(i => i.InkomstLabels).First();

            inkomst.Persoon         = inkomstVM.Persoon;
            inkomst.Bedrag          = inkomstVM.Bedrag;
            inkomst.Begindatum      = inkomstVM.Begindatum;
            inkomst.Einddatum       = inkomstVM.Einddatum;
            inkomst.Interval        = inkomstVM.Interval;
            inkomst.LaatstGewijzigd = DateTime.Now;

            inkomst.InkomstLabels.Clear();

            foreach (var newLabelId in inkomstVM.Label)
            {
                Label label = _context.Label.Where(l => l.Id == newLabelId).First();
                inkomst.InkomstLabels.Add
                (
                    nieuwInkomstLabel(inkomst, label)
                );
            }

            _context.Entry(inkomst).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!InkomstExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #27
0
        public async Task <IActionResult> PutSpaardoel([FromRoute] int id, [FromBody] SpaardoelPostModel spaardoelPM)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != spaardoelPM.Id)
            {
                return(BadRequest());
            }

            Spaardoel spaardoel = _context.Spaardoel.Where(r => r.Id == id).Include(r => r.SpaardoelLabels).First();

            spaardoel.Percentage      = spaardoelPM.Percentage;
            spaardoel.Eindbedrag      = spaardoelPM.Eindbedrag;
            spaardoel.EersteMaand     = spaardoelPM.EersteMaand;
            spaardoel.LaatsteMaand    = spaardoelPM.LaatsteMaand;
            spaardoel.Omschrijving    = spaardoelPM.Omschrijving;
            spaardoel.LaatstGewijzigd = DateTime.Now;

            spaardoel.SpaardoelLabels.Clear();

            foreach (var newLabelId in spaardoelPM.Label)
            {
                Label label = _context.Label.Where(l => l.Id == newLabelId).First();
                spaardoel.SpaardoelLabels.Add
                (
                    nieuwSpaardoelLabel(spaardoel, label)
                );
            }

            _context.Entry(spaardoel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SpaardoelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #28
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,OrderId,ItemId,Quantity")] OrderItem orderItem)
        {
            if (ModelState.IsValid)
            {
                db.Entry(orderItem).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.ItemId  = new SelectList(db.Items, "Id", "Name", orderItem.ItemId);
            ViewBag.OrderId = new SelectList(db.Orders, "Id", "OrderNo", orderItem.OrderId);
            return(View(orderItem));
        }
예제 #29
0
        public ActionResult OnGet()
        {
            this.Success = string.Empty;
            this.Error   = string.Empty;
            string userEmail = this.HttpContext.User.Identity.Name;

            if (string.IsNullOrEmpty(userEmail))
            {
                return(Redirect("~/login"));
            }

            this.CurrentUser = context.Set <Models.User>().Where(entry => entry.Email.Equals(userEmail)).FirstOrDefault();
            if (this.CurrentUser == null)
            {
                return(Redirect("~/login"));
            }
            else
            {
                context.Entry(this.CurrentUser).Collection(u => u.UserInfo).Load();
                return(Page());
            }
        }
예제 #30
0
        public async Task <IActionResult> PutBudget([FromRoute] int id, [FromBody] BudgetPostModel budgetPM)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != budgetPM.Id)
            {
                return(BadRequest());
            }

            Budget budget = _context.Budget.Where(i => i.Id == id).Include(i => i.BudgetLabels).First();

            budget.Bedrag          = budgetPM.Bedrag;
            budget.Begindatum      = budgetPM.Begindatum;
            budget.Einddatum       = budgetPM.Einddatum;
            budget.Interval        = budgetPM.Interval;
            budget.LaatstGewijzigd = DateTime.Now;

            budget.BudgetLabels.Clear();

            foreach (var newLabelId in budgetPM.Label)
            {
                Label label = _context.Label.Where(l => l.Id == newLabelId).First();
                budget.BudgetLabels.Add
                (
                    nieuwBudgetLabel(budget, label)
                );
            }

            _context.Entry(budget).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BudgetExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }