コード例 #1
0
        public async Task <IActionResult> Post([FromBody] OogstkaartItem oogstkaartItem)
        {
            var now  = DateTime.Now;
            var user = await _usermanager.GetUserAsync(User);

            if (ModelState.IsValid)
            {
                oogstkaartItem.OnlineStatus = true;
                oogstkaartItem.UserID       = user.Id;
                oogstkaartItem.CreateDate   = now;

                //verwijder lege specificaties die leeg zijn.
                foreach (var spec in oogstkaartItem.Specificaties)
                {
                    if (spec.SpecificatieSleutel == null || spec.SpecificatieValue == null)
                    {
                        oogstkaartItem.Specificaties.Remove(spec);
                    }
                }

                await _context.OogstkaartItems.AddAsync(oogstkaartItem);

                await _context.SaveChangesAsync();

                return(Ok(oogstkaartItem.OogstkaartItemID));
            }

            return(BadRequest());
        }
コード例 #2
0
        public async Task <IActionResult> Post([FromBody] OogstkaartItem oogstkaartItem)
        {
            var now = DateTime.Now;

            var user = await Usermanager.GetUserAsync(User);

            if (ModelState.IsValid)
            {
                oogstkaartItem.OnlineStatus = true;
                oogstkaartItem.UserID       = user.Id;
                oogstkaartItem.CreateDate   = now;
                await context.OogstkaartItems.AddAsync(oogstkaartItem);

                await context.SaveChangesAsync();

                return(Ok(oogstkaartItem.OogstkaartItemID));
            }

            return(BadRequest());
        }
コード例 #3
0
        public async Task <IActionResult> Update([FromBody] OogstkaartItem updatingitem)
        {
            var user = await _usermanager.GetUserAsync(User);

            if (user != null)
            {
                var item = await _context.OogstkaartItems.Where(i => i.OogstkaartItemID == updatingitem.OogstkaartItemID)
                           .Where(i => i.UserID == user.Id).Include(i => i.Views).Include(i => i.Location).Include(i => i.Specificaties).FirstOrDefaultAsync();

                if (item == null)
                {
                    return(NotFound());
                }


                item.Artikelnaam      = updatingitem.Artikelnaam;
                item.Category         = updatingitem.Category;
                item.Concept          = updatingitem.Concept;
                item.CreateDate       = updatingitem.CreateDate;
                item.DatumBeschikbaar = updatingitem.DatumBeschikbaar;
                item.Hoeveelheid      = updatingitem.Hoeveelheid;
                item.Jansenserie      = updatingitem.Jansenserie;

                item.Omschrijving         = updatingitem.Omschrijving;
                item.VraagPrijsPerEenheid = updatingitem.VraagPrijsPerEenheid;
                item.VraagPrijsTotaal     = updatingitem.VraagPrijsTotaal;

                item.Location.Latitude   = updatingitem.Location.Latitude;
                item.Location.Longtitude = updatingitem.Location.Longtitude;


                //bekijk alle specificaties dat wel in de lijst voorkomen en update die

                foreach (var tempspec in updatingitem.Specificaties)
                {
                    var spec = await _context.Specificaties.FirstOrDefaultAsync(i => i.SpecificatieID == tempspec.SpecificatieID);

                    if (spec == null)
                    {
                        item.Specificaties.Add(tempspec);
                    }
                    else
                    {
                        spec.SpecificatieSleutel      = tempspec.SpecificatieSleutel;
                        spec.SpecificatieEenheid      = tempspec.SpecificatieEenheid;
                        spec.SpecificatieValue        = tempspec.SpecificatieValue;
                        spec.SpecificatieOmschrijving = tempspec.SpecificatieOmschrijving;
                    }
                }


                //bekijk of er zaken verwijderd moeten worden die niet in de geüpdate lijst voorkomen
                foreach (var spec in item.Specificaties)
                {
                    var sp = updatingitem.Specificaties.FirstOrDefault(i => i.SpecificatieID == spec.SpecificatieID);
                    if (sp == null)
                    {
                        _context.Specificaties.Remove(spec);
                    }
                }

                //verwijder lege specificaties die leeg zijn.
                var specs = item.Specificaties.Where(i => i.SpecificatieValue == null || i.SpecificatieSleutel == null).ToList();
                foreach (var sp in specs)
                {
                    item.Specificaties.Remove(sp);
                }

                _context.OogstkaartItems.Update(item);
                await _context.SaveChangesAsync();

                EmailMessage mail = new EmailMessage();
                mail.FromAddresses.Add(new EmailAddress {
                    Address = user.Email
                });
                mail.Subject = string.Format("Product {0}  werd aangepast op de oogstkaart op {1} ", item.Artikelnaam, DateTime.Now.ToShortDateString());
                mail.ToAddresses.Add(new EmailAddress {
                    Address = "*****@*****.**"
                });
                mail.Content = string.Format("Product ({0}) werd aangepast op de oogstkaart. <a href='http://jansenbyods.com/oogstkaart/{1}'>Bekijk product.</a>", item.Artikelnaam, item.OogstkaartItemID.ToString());
                await _emailservice.Send(mail);



                return(Ok());
            }

            return(BadRequest());
        }