Example #1
0
        public async Task <Response> AddMeal(Guid id, MealDto dto)
        {
            var st = await GetStudentFullDetails(id);

            if (st != null)
            {
                if (st.Parents.Count > 0)
                {
                    var p = st.Parents.First();
                    st.AddMeal(dto.MealType, dto.POSId);
                    _context.Students.Update(st);
                    //SMS
                    var s = SMSLog.Create(p.Phone, $"Dear {p.Name.First} student has ordered a meal on {DateTime.UtcNow} ...");
                    _context.SMSLogs.Add(s);
                    await _context.SaveChangesAsync();

                    //Email
                    _emailService.SendMail(p.Email, "Meal Notice", $"Dear {p.Name.First} student has ordered a meal on {DateTime.UtcNow} ...");
                    return(new Response());
                }
                return(new Response(new List <string> {
                    "Parent not found"
                }));
            }
            return(new Response(new List <string> {
                "Student not found"
            }));
        }