Exemplo n.º 1
0
        public void UpdateWork(UpdateWorkDto updateWorkDto)
        {
            var work = Db.Works.Where(x => x.Id == updateWorkDto.Id).SingleOrDefault();

            work.Title       = updateWorkDto.Title;
            work.Description = updateWorkDto.Description;
            Db.SaveChanges();
        }
        public async Task <IActionResult> UpdateActivityTaskWork(UpdateWorkDto updateWorkDto, [FromRoute] string id)
        {
            var activityTask = await _context.ActivityTask.Include(p => p.Schedule).Include(i => i.Activity)
                               .Where(p => p.ActivityTaskId == Int32.Parse(id)).FirstOrDefaultAsync();


            if (activityTask == null)
            {
                return(BadRequest());
            }

            System.Diagnostics.Debug.WriteLine(activityTask.ActiveSchedule.TimeFrom + " " + activityTask.ActiveSchedule.TimeTo + " " +
                                               updateWorkDto.timeFrom + " " + updateWorkDto.timeTo);


            if (updateWorkDto.workedOnTask == "yes")
            {
                System.Diagnostics.Debug.WriteLine("uso1");

                if (updateWorkDto.timeFrom == activityTask.ActiveSchedule.TimeFrom && updateWorkDto.timeTo == activityTask.ActiveSchedule.TimeTo)
                {
                    System.Diagnostics.Debug.WriteLine("ovdi");

                    activityTask.ActiveSchedule.TimeWorked = updateWorkDto.timeTo - updateWorkDto.timeFrom;
                    activityTask.DonePercentage            = (updateWorkDto.timeTo - updateWorkDto.timeFrom) + "/" + activityTask.Duration;
                    _context.Entry(activityTask).State     = EntityState.Modified;
                    await _context.SaveChangesAsync();
                }
                else
                {
                    activityTask.ActiveSchedule.TimeWorked = updateWorkDto.timeTo - updateWorkDto.timeFrom;
                    activityTask.DonePercentage            = (updateWorkDto.timeTo - updateWorkDto.timeFrom) + "/" + activityTask.Duration;

                    var activity = _context.Activity.Include(o => o.User).Where(a => a.ActivityId == activityTask.ActivityId).FirstOrDefault();

                    var at = _context.UserActivityType.Include(a => a.ActivityType).ThenInclude(a => a.Activity)
                             .Where(a => a.ActivityTypeId == activity.ActivityTypeId && a.UserId == activity.UserId).FirstOrDefault();


                    DateTime day      = DateTime.Today;
                    int      potrebno = (activityTask.ActiveSchedule.TimeTo - activityTask.ActiveSchedule.TimeFrom) - activityTask.ActiveSchedule.TimeWorked;

                    while (true)
                    {
                        string          shortDay  = day.ToShortDateString();
                        List <Schedule> schedules = _context.Schedule.Include(p => p.ActivityTask).ThenInclude(a => a.Activity).ThenInclude(o => o.User)
                                                    .AsEnumerable()
                                                    .Where(a => a.Date.ToShortDateString() == shortDay && a.ActivityTask.Activity.UserId == activity.UserId).ToList();

                        if (!schedules.Any()) //prazan raspored taj dan
                        {
                            Schedule newSchedule = new Schedule {
                                TimeTo = activityTask.ActiveSchedule.TimeFrom + potrebno, TimeFrom = activityTask.ActiveSchedule.TimeFrom, Date = day, Moveable = false
                            };
                            activityTask.Schedule.Add(newSchedule);

                            _context.Schedule.Add(newSchedule);
                            await _context.SaveChangesAsync();

                            break;
                        }
                        day = day.AddDays(1);
                    }
                }
            }
            else
            {
                activityTask.ActiveSchedule.TimeWorked = 0;

                var activity = _context.Activity.Include(o => o.User).Where(a => a.ActivityId == activityTask.ActivityId).FirstOrDefault();

                var at = _context.UserActivityType.Include(a => a.ActivityType).ThenInclude(a => a.Activity)
                         .Where(a => a.ActivityTypeId == activity.ActivityTypeId && a.UserId == activity.UserId).FirstOrDefault();


                DateTime day = DateTime.Today;

                while (true)
                {
                    string          shortDay  = day.ToShortDateString();
                    List <Schedule> schedules = _context.Schedule.Include(p => p.ActivityTask).ThenInclude(a => a.Activity).ThenInclude(o => o.User)
                                                .AsEnumerable()
                                                .Where(a => a.Date.ToShortDateString() == shortDay && a.ActivityTask.Activity.UserId == activity.UserId).ToList();

                    if (!schedules.Any()) //prazan raspored taj dan
                    {
                        Schedule newSchedule = new Schedule {
                            TimeTo = activityTask.ActiveSchedule.TimeTo, TimeFrom = activityTask.ActiveSchedule.TimeFrom, Date = day, Moveable = false
                        };
                        activityTask.Schedule.Add(newSchedule);

                        _context.Schedule.Add(newSchedule);
                        await _context.SaveChangesAsync();

                        break;
                    }
                    day = day.AddDays(1);
                }
            }


            _context.Entry(activityTask).State = EntityState.Modified;
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ActivityTaskExists(Int32.Parse(id)))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 3
0
 public void Edit([FromBody] UpdateWorkDto work)
 {
     developerRepository.UpdateWork(work);
 }
Exemplo n.º 4
0
 public IActionResult EditWork(UpdateWorkDto UpdateWorkDto)
 {
     developerRepository.UpdateWork(UpdateWorkDto);
     return(RedirectToAction("ShowProjects"));
 }