Пример #1
0
        public ActionResult <NewRecordResponse> Post([FromBody] StudentRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var student = new Student
                {
                    FirstName  = request.FirstName,
                    MiddleName = request.MiddleName,
                    LastName   = request.LastName,
                    BirthDate  = request.BirthDate,
                    Gender     = Gender.FromId(request.Gender) ?? Gender.NotSpecified,
                    GPA        = request.Gpa
                };

                this.studentRepository.Create(student);

                var response = new NewRecordResponse(student.Id);

                return(CreatedAtAction(nameof(Get), new { id = student.Id }, response));
            }
            catch (Exception e)
            {
                return(GenericServerErrorResult(e));
            }
        }
        public ActionResult <NewRecordResponse> Post([FromBody] TeacherRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var teacher = new Teacher
                {
                    FirstName  = request.FirstName,
                    MiddleName = request.MiddleName,
                    LastName   = request.LastName,
                    BirthDate  = request.BirthDate,
                    Gender     = Gender.FromId(request.Gender) ?? Gender.NotSpecified,
                    Title      = NameTitle.FromId(request.Title) ?? NameTitle.None
                };

                this.teacherRepository.Create(teacher);

                var response = new NewRecordResponse(teacher.Id);

                return(CreatedAtAction(nameof(Get), new { id = teacher.Id }, response));
            }
            catch (Exception e)
            {
                return(GenericServerErrorResult(e));
            }
        }
Пример #3
0
        public ActionResult <NewRecordResponse> Post([FromBody] SubjectRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var subject = new Subject
                {
                    Name        = request.Name,
                    Description = request.Description
                };

                this.subjectRepository.Create(subject);

                var response = new NewRecordResponse(subject.Id);

                return(CreatedAtAction(nameof(Get), new { id = subject.Id }, response));
            }
            catch (Exception e)
            {
                return(GenericServerErrorResult(e));
            }
        }
Пример #4
0
 public RaiseNewIssue()
 {
     InitializeComponent();
     if (LoggedInUser.userType.Equals(Constants.UserType.NGO) || LoggedInUser.userType.Equals(Constants.UserType.AUTHORITY))
     {
         base.OnBackButtonPressed();
     }
     rating.SelectedIndex = 4;
     aPIService           = RestService.For <IAPIService>(Constants.mongoDBBaseUrl);
     insertIssues         = new InsertIssues();
     newRecordResponse    = new NewRecordResponse();
     ((NavigationPage)Application.Current.MainPage).BarBackgroundColor = Color.Black;
     ((NavigationPage)Application.Current.MainPage).BarTextColor       = Color.White;
 }
Пример #5
0
        public ActionResult <NewRecordResponse> Post([FromBody] ClassScheduleRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                //List<Student> students = new List<Student>();
                //if (request.Students != null)
                //{
                //	students = request.Students.Select(studentId => new Student
                //	{
                //		Id = studentId
                //	}).ToList();
                //}

                //TODO: This is sloppy, fix this :(

                var subject = subjectRepository.Get(request.Subject);
                if (subject == null)
                {
                    return(BadRequest());
                }

                var teacher = teacherRepository.Get(request.Teacher);
                if (subject == null)
                {
                    return(BadRequest());
                }

                var classSchedule = new ClassSchedule
                {
                    Location = request.Location,
                    Subject  = subject,
                    Teacher  = teacher
                };

                this.classScheduleRepository.Create(classSchedule);

                var response = new NewRecordResponse(classSchedule.Id);

                return(CreatedAtAction(nameof(Get), new { id = classSchedule.Id }, response));
            }
            catch (Exception e)
            {
                return(GenericServerErrorResult(e));
            }
        }
Пример #6
0
        private async void UploadIssue_Clicked(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(stream) || string.IsNullOrEmpty(area_issue.Text) || string.IsNullOrEmpty(area_issue.Text) || string.IsNullOrEmpty(Comments.Text))
            {
                await DisplayAlert("Empty Field", "Please Fill The Fields", "Ok");

                return;
            }
            insertIssues.adder = LoggedInUser.userID;
            insertIssues.additional_comments = Comments.Text;
            insertIssues.address             = area_issue.Text;
            insertIssues.event_id            = "NONE";
            insertIssues.photo             = stream;
            insertIssues.rating            = rating.SelectedItem.ToString();
            insertIssues.status            = "OPEN";
            insertIssues.status_changed_by = "NONE";

            MyActivityIndicator.IsVisible = true;
            try
            {
                newRecordResponse = await aPIService.InsertNewIssue(Constants.mongoDBBName, Constants.mongoDBCollectionIssues, Constants.mongoDBKey, insertIssues);

                MyActivityIndicator.IsVisible = false;

                if (!string.IsNullOrEmpty(newRecordResponse._id.oid))
                {
                    await DisplayAlert("Success", "Successsfully Inserted The Record.", "ok");

                    await this.Navigation.PopAsync();
                }
                else
                {
                    await DisplayAlert("Failure", "Failed To Insert The Record.", "ok");
                }
            }
            catch (ApiException apiException)
            {
                this.newRecordResponse = null;
                MongoCache.WriteOfflineIssue(insertIssues);
                await DisplayAlert("Failure", "Failed To Insert The Record. Will Try again when the internet is back.", "ok");

                await this.Navigation.PopAsync();
            }
        }
Пример #7
0
        protected override async void OnStart()
        {
            // Handle when your app starts
            issuesToBeUploaded = MongoCache.ReadOfflineIssue();
            eventsToBeUploaded = MongoCache.ReadOfflineEvent();

            if (issuesToBeUploaded != null)
            {
                newRecordResponse = new NewRecordResponse();
                aPIService        = RestService.For <IAPIService>(Constants.mongoDBBaseUrl);
                int currentIssue = 0;

                if (issuesToBeUploaded.Count > 0)
                {
                    try
                    {
                        foreach (var issue in issuesToBeUploaded)
                        {
                            newRecordResponse = await aPIService.InsertNewIssue(Constants.mongoDBBName, Constants.mongoDBCollectionIssues, Constants.mongoDBKey, issue);

                            if (!string.IsNullOrEmpty(newRecordResponse._id.oid))
                            {
                                // This is Success.

                                /*
                                 * First, we get the issue list from application settings and then we iterate over each and every saved instance.
                                 * Now, when we have success, we remove that item, so that it doesn't appear again in the list.
                                 * Now, we need to increment the issue count.
                                 */
                                issuesToBeUploaded.RemoveAt(currentIssue);
                                currentIssue++;
                            }
                            else
                            {
                                // This is Failure.
                                Console.WriteLine("Failure Occurred. Moving To Next One.");
                            }
                        }
                        foreach (var item in issuesToBeUploaded)
                        {
                            MongoCache.WriteOfflineIssue(item);
                        }
                    }
                    catch (Exception ex)
                    {
                        // Move On.
                        Console.WriteLine("Error While Uploading Issue Backlog : " + ex.Message);
                    }
                }
            } // Issue Uploaded

            if (eventsToBeUploaded != null)
            {
                newEventResponse = new Event();
                aPIService       = RestService.For <IAPIService>(Constants.mongoDBBaseUrl);
                int currentEvent = 0;

                if (eventsToBeUploaded.Count > 0)
                {
                    try
                    {
                        foreach (var eventVal in eventsToBeUploaded)
                        {
                            newEventResponse = await aPIService.InsertNewEvent(Constants.mongoDBBName, Constants.mongoDBCollectionEvents, Constants.mongoDBKey, eventVal);

                            if (!string.IsNullOrEmpty(newEventResponse._id.oid))
                            {
                                // This is Success.

                                /*
                                 * First, we get the event list from application settings and then we iterate over each and every saved instance.
                                 * Now, when we have success, we remove that item, so that it doesn't appear again in the list.
                                 * Now, we need to increment the issue count.
                                 */
                                eventsToBeUploaded.RemoveAt(currentEvent);
                                currentEvent++;
                            }
                            else
                            {
                                // This is Failure.
                                Console.WriteLine("Failure Occurred. Moving To Next One.");
                            }
                        }

                        foreach (var item in eventsToBeUploaded)
                        {
                            MongoCache.WriteOfflineEvent(item);
                        }
                    }
                    catch (Exception ex)
                    {
                        // Move On.
                        Console.WriteLine("Error While Uploading Event Backlog : " + ex.Message);
                    }
                }
            } // Event Uploaded
        }