Example #1
0
        public JsonResult UpdateCalender([FromBody] CalendarTask model)
        {
            int    employeeId        = model.EmployeeId;
            string calendarViewType  = model.CalendarViewType;
            string calendarStartDate = model.CalendarStartDate;
            string calendarEndDate   = model.CalendarEndDate;
            var    calendarTasks     = JsonConvert.DeserializeObject <IEnumerable <JsonEmployeeTask> >(model.Events);
            var    user = new UserDto
            {
                Id = employeeId,
                CalendarViewType = calendarViewType
            };
            var dtCalendarDate = DateTime.Parse(calendarStartDate, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind);

            user.CalendarStartDate = dtCalendarDate;
            dtCalendarDate         = DateTime.Parse(calendarEndDate, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind);
            user.CalendarEndDate   = dtCalendarDate;
            foreach (var calendarTask in calendarTasks)
            {
                DateTime.TryParse(calendarTask.start, out DateTime startDate);
                DateTime.TryParse(calendarTask.end, out DateTime endDate);
                var task = new UserPersonTaskDto
                {
                    Id                = (int)calendarTask.id,
                    Description       = calendarTask.id == 0 ? calendarTask.title : calendarTask.description,
                    TaskName          = calendarTask.title,
                    UserId            = employeeId,
                    ScheduleStartTime = startDate,
                    ScheduleEndTime   = endDate == DateTime.MinValue ? startDate.AddMinutes(30) : endDate,
                };
                UpdateAuditInformation(task);
                user.Tasks.Add(task);
            }
            var result  = _employeeFacadeApiClient.PatchUserTasks(user.Id, user).Result;
            var message = string.IsNullOrWhiteSpace(result.ErrorMessage) ? result.SuccessMessage : result.ErrorMessage;

            return(Json(new { message, employeeId, success = string.IsNullOrWhiteSpace(result.ErrorMessage) }));
        }