Exemplo n.º 1
0
        public async Task <IActionResult> Create(Lawn lawn)
        {
            if (ModelState.IsValid)
            {
                _context.Add(lawn);
                await _context.SaveChangesAsync();



                //text message for this method
                ////////
                SMSInformation twilio = new SMSInformation();

                string accountSid = twilio.accountSID;
                string authToken  = twilio.accountToken;

                TwilioClient.Init(accountSid, authToken);

                var message = MessageResource.Create(
                    body: $"Hi, {lawn.FirstName}, your lawn at {lawn.StreetAddress} has been requested, and you will be notified if it is approved.",
                    from: new Twilio.Types.PhoneNumber(twilio.twilioPhone),
                    to: new Twilio.Types.PhoneNumber(twilio.customerPhone));
                /////////



                return(RedirectToAction(nameof(Index)));
            }
            return(View(lawn));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,FirstName,LastName,Phone, StreetAddress,City,State,ZipCode,Size,Description,Approved,Photo")] Lawn lawn)
        {
            if (id != lawn.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(lawn);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LawnExists(lawn.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                //if lawn is approved, then send a text and send user to create the first service entry, otherwise store it as denied and do nothing with it
                if (lawn.Approved == true)
                {
                    //text message for this method
                    ////////
                    SMSInformation twilio = new SMSInformation();

                    string accountSid = twilio.accountSID;
                    string authToken  = twilio.accountToken;

                    TwilioClient.Init(accountSid, authToken);

                    var message = MessageResource.Create(
                        body: $"Hi, {lawn.FirstName}, your lawn at {lawn.StreetAddress} has been approved, and it will be added to the queue for mowing.",
                        from: new Twilio.Types.PhoneNumber(twilio.twilioPhone),
                        to: new Twilio.Types.PhoneNumber(twilio.customerPhone));
                    /////////



                    return(RedirectToAction("Create", "Services", new { id = lawn.Id }));
                }
                else
                {
                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View(lawn));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Edit(int id, Service service)
        {
            if (id != service.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    //give a completed date
                    service.CompletedDate = DateTime.Now;
                    _context.Update(service);
                    await _context.SaveChangesAsync();


                    //text message for this method
                    ////////
                    SMSInformation twilio = new SMSInformation();

                    string accountSid = twilio.accountSID;
                    string authToken  = twilio.accountToken;

                    TwilioClient.Init(accountSid, authToken);

                    var message = MessageResource.Create(
                        body: $"Your lawn has a voLAWNteer, and they will be coming soon to mow your lawn!",
                        from: new Twilio.Types.PhoneNumber(twilio.twilioPhone),
                        to: new Twilio.Types.PhoneNumber(twilio.customerPhone));
                    /////////
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ServiceExists(service.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                //send user to create new service listing and send the FK with it
                return(RedirectToAction("Create", "Services", new { id = service.LawnId }));
            }
            return(View(service));
        }