Exemple #1
0
        public async Task <IActionResult> PutRegOfIntrest(string id, RegOfIntrest regOfIntrest)
        {
            if (id != regOfIntrest.CustomerEmail)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <ActionResult <RegOfIntrest> > RegOfIntrest(int houseObjectId, Customer customer)
        {
            // Kollar om husobjektet finns.
            var house = await _context.HouseObjects.FindAsync(houseObjectId);

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

            // Skapar upp en ny "customer", ifall den inte redan existerar, och vi kollar då på email.
            if (!CustomerExists(customer.Email))
            {
                _context.Customers.Add(customer);
                await _context.SaveChangesAsync();
            }


            var subscription = new RegOfIntrest()
            {
                HouseObjectId = houseObjectId, CustomerEmail = customer.Email
            };

            // Här kollar vi om kunden redan har en intresseanmälan på "det" objektet.
            if (RegOfIntrestExists(subscription.HouseObjectId, subscription.CustomerEmail))
            {
                return(Conflict());
            }

            // Slutligen gör en Intresseanmälan.
            _context.RegOfIntrests.Add(subscription);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                throw;
            }

            return(subscription);
        }
Exemple #3
0
        public async Task <ActionResult <RegOfIntrest> > PostRegOfIntrest(RegOfIntrest regOfIntrest)
        {
            _context.RegOfIntrests.Add(regOfIntrest);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (RegOfIntrestExists(regOfIntrest.CustomerEmail))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetRegOfIntrest", new { id = regOfIntrest.CustomerEmail }, regOfIntrest));
        }