Ejemplo n.º 1
0
        /// <summary>
        /// Finds Effort By Id
        /// </summary>
        /// <param name="id">Injected <see cref="int"/></param>
        /// <returns>Instance of <see cref="Task{Effort}"/></returns>
        public async Task <Effort> FindEffortById(int @id)
        {
            Effort @effort = await Context.Effort
                             .TagWith("FindEffortById")
                             .FirstOrDefaultAsync(x => x.Id == @id);

            if (@effort == null)
            {
                // Log
                string @logData = @effort.GetType().Name
                                  + " with Id "
                                  + @id
                                  + " was not found at "
                                  + DateTime.Now.ToShortTimeString();

                Logger.WriteGetItemNotFoundLog(@logData);

                throw new Exception(@effort.GetType().Name
                                    + " with Id "
                                    + @id
                                    + " does not exist");
            }

            return(@effort);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// De Activates Stop
        /// </summary>
        /// <param name="viewmodel">Injected <see cref="AddEffort"/></param>
        /// <returns>Instance of <see cref="Task"/></returns>
        public async Task DeActivateStop(AddEffort @viewmodel)
        {
            Effort @effort = await this.FindFormerDayActiveEffortByApplicationUserId(@viewmodel.ApplicationUserId);

            if (@effort != null)
            {
                if (@effort.Kind.Id.Equals((int)EffortKinds.Stop))
                {
                    @effort.Active = false;
                    @effort.Finish = DateTime.Now;

                    Context.Effort.Update(@effort);

                    // Log
                    string @logData = @effort.GetType().Name
                                      + " with Id "
                                      + @effort.Id
                                      + " was updated at "
                                      + DateTime.Now.ToShortTimeString();

                    Logger.WriteUpdateItemLog(@logData);
                }
                else
                {
                    throw new Exception(@effort.GetType().Name
                                        + " with Id "
                                        + @effort.Id
                                        + " can not be stopped");
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// De Activates Resume
        /// </summary>
        /// <param name="viewmodel">Injected <see cref="AddEffort"/></param>
        /// <returns>Instance of <see cref="Task"/></returns>
        public async Task DeActivateResume(AddEffort @viewmodel)
        {
            Effort @effort = await FindCurrentDayActiveEffortByApplicationUserId(@viewmodel.ApplicationUserId);

            if (@effort != null)
            {
                if (@effort.Kind.Id.Equals((int)EffortKinds.Resume) || @effort.Kind.Id.Equals((int)EffortKinds.Start))
                {
                    effort.ApplicationUser = await FindApplicationUserById(@viewmodel.ApplicationUserId);

                    @effort.Active = false;
                    @effort.Finish = DateTime.Now;

                    Context.Effort.Update(@effort);

                    // Log
                    string @logData = @effort.GetType().Name
                                      + " with Id "
                                      + @effort.Id
                                      + " was updated at "
                                      + DateTime.Now.ToShortTimeString();

                    Logger.WriteUpdateItemLog(@logData);
                }
                else
                {
                    throw new Exception(@effort.GetType().Name
                                        + " with Id "
                                        + @effort.Id
                                        + " can not be stoppped");
                }
            }
            else
            {
                // Log
                string @logData = @effort.GetType().Name
                                  + " for Application User"
                                  + viewmodel.ApplicationUserId
                                  + " was not found at "
                                  + DateTime.Now.ToShortTimeString();

                Logger.WriteGetItemNotFoundLog(@logData);

                throw new Exception(@effort.GetType().Name
                                    + " was not started");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Stops
        /// </summary>
        /// <param name="viewmodel">Injected <see cref="AddEffort"/></param>
        /// <returns>Instance of <see cref="Task{ViewEffort}"/></returns>
        public async Task <ViewEffort> Stop(AddEffort @viewmodel)
        {
            await DeActivateResume(@viewmodel);

            Effort @effort = await AddStopEffort(@viewmodel);

            await Context.SaveChangesAsync();

            // Log
            string @logData = @effort.GetType().Name
                              + " with Id "
                              + @effort.Id
                              + " was added at "
                              + DateTime.Now.ToShortTimeString();

            Logger.WriteInsertItemLog(@logData);

            return(Mapper.Map <ViewEffort>(@effort));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Removes Effort By Id
        /// </summary>
        /// <param name="id">Injected <see cref="int"/></param>
        /// <returns>Instance of <see cref="Task"/></returns>
        public async Task RemoveEffortById(int @id)
        {
            try
            {
                Effort @effort = await FindEffortById(@id);

                Context.Effort.Remove(@effort);

                await Context.SaveChangesAsync();

                // Log
                string @logData = @effort.GetType().Name
                                  + " with Id "
                                  + @effort.Id
                                  + " was removed at "
                                  + DateTime.Now.ToShortTimeString();

                Logger.WriteDeleteItemLog(@logData);
            }
            catch (DbUpdateConcurrencyException)
            {
                await FindEffortById(@id);
            }
        }