Пример #1
0
 private Time ToTime(NewTimeRequest request)
 {
     return(new Time
     {
         ActivityId = request.ActivityId,
         DateRegistered = DateTime.Now,
         DateReported = request.DateReported,
         EmployeeId = request.EmployeeId,
         From = request.From,
         Latitude = request.Latitude,
         Longitude = request.Longitude,
         ProjectId = request.ProjectId,
         Remarks = request.Remarks,
         To = request.To,
     });
 }
Пример #2
0
		async void Save()
		{
			if (ProjectId == 0)
			{
				await dialogService.ShowMessage("Error", "You must select a project.");
				return;
			}

			if (ActivityId == 0)
			{
				await dialogService.ShowMessage("Error", "You must select an activity.");
				return;
			}

			ConvertHours();

			if (To <= From)
			{
				await dialogService.ShowMessage("Error", "The hour 'To' must be greather hour 'From'.");
				return;
			}

			IsEnabled = false;
			IsRunning = true;

			var checkConnetion = await apiService.CheckConnection();
			if (!checkConnetion.IsSuccess)
			{
				IsRunning = false;
				IsEnabled = true;
				await dialogService.ShowMessage("Error", checkConnetion.Message);
				return;
			}

			var urlAPI = Application.Current.Resources["URLAPI"].ToString();
			var mainViewModel = MainViewModel.GetInstance();
			var employee = mainViewModel.Employee;

			await geolocatorService.GetLocation();

			var newTimeRequest = new NewTimeRequest
			{
				ActivityId = ActivityId,
				DateReported = DateReported,
				EmployeeId = employee.EmployeeId,
				From = From,
				Latitude = geolocatorService.Latitude,
				Longitude = geolocatorService.Longitude,
				IsRepeated = IsRepeated,
				IsRepeatFriday = IsRepeatFriday,
				IsRepeatMonday = IsRepeatMonday,
				IsRepeatSaturday = IsRepeatSaturday,
				IsRepeatSunday = IsRepeatSunday,
				IsRepeatThursday = IsRepeatThursday,
				IsRepeatTuesday = IsRepeatTuesday,
				IsRepeatWednesday = IsRepeatWednesday,
				ProjectId = ProjectId,
				Remarks = Remarks,
				To = To,
				Until = Until,
			};

			var response = await apiService.Post(
				urlAPI,
				"/api",
				"/Times",
				employee.TokenType,
				employee.AccessToken,
				newTimeRequest);

			IsEnabled = true;
			IsRunning = false;

			if (!response.IsSuccess)
			{
				await dialogService.ShowMessage("Error", response.Message);
				return;
			}

			await navigationService.Back();
		}
Пример #3
0
        // POST: api/Times
        public async Task <IHttpActionResult> PostTime(NewTimeRequest request)
        {
            Time time = null;

            if (!request.IsRepeated)
            {
                time = ToTime(request);
                db.Times.Add(time);
            }
            else
            {
                var date = request.DateReported;
                while (date <= request.Until)
                {
                    var sw = false;

                    if (date.DayOfWeek == DayOfWeek.Monday && request.IsRepeatMonday)
                    {
                        sw = true;
                    }

                    if (date.DayOfWeek == DayOfWeek.Tuesday && request.IsRepeatTuesday)
                    {
                        sw = true;
                    }

                    if (date.DayOfWeek == DayOfWeek.Wednesday && request.IsRepeatWednesday)
                    {
                        sw = true;
                    }

                    if (date.DayOfWeek == DayOfWeek.Thursday && request.IsRepeatThursday)
                    {
                        sw = true;
                    }

                    if (date.DayOfWeek == DayOfWeek.Friday && request.IsRepeatFriday)
                    {
                        sw = true;
                    }

                    if (date.DayOfWeek == DayOfWeek.Saturday && request.IsRepeatSaturday)
                    {
                        sw = true;
                    }

                    if (date.DayOfWeek == DayOfWeek.Sunday && request.IsRepeatSunday)
                    {
                        sw = true;
                    }

                    if (sw)
                    {
                        time = new Time
                        {
                            ActivityId     = request.ActivityId,
                            DateRegistered = DateTime.Now,
                            DateReported   = date,
                            EmployeeId     = request.EmployeeId,
                            From           = request.From,
                            Latitude       = request.Latitude,
                            Longitude      = request.Longitude,
                            ProjectId      = request.ProjectId,
                            Remarks        = request.Remarks,
                            To             = request.To,
                        };

                        db.Times.Add(time);
                    }

                    date = date.AddDays(1);
                }
            }

            await db.SaveChangesAsync();

            return(Ok(time));
        }