Пример #1
0
        public async Task <bool> Delete(Models.Activity activity)
        {
            if (activity == null)
            {
                return(false);
            }
            if (activity.Id == null)
            {
                return(false);
            }
            if (activity.Id == "")
            {
                return(false);
            }
            try
            {
                Models.Activity activityGet = await TimeSheetContext.Activity.Where(x => x.Id == activity.Id).SingleOrDefaultAsync();

                if (activityGet == null)
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                return(false);
            }
            TimeSheetContext.Remove(activity);
            await TimeSheetContext.SaveChangesAsync();

            return(true);
        }
Пример #2
0
        public async Task <bool> Delete(Models.Log log)
        {
            log = await Get(log);

            if (log == null)
            {
                return(false);
            }
            TimeSheetContext.Remove(log);
            await TimeSheetContext.SaveChangesAsync();

            return(true);
        }
Пример #3
0
        public async Task <bool> Delete(Models.Project project)
        {
            project = await GetSmall(project);

            if (project == null)
            {
                return(false);
            }
            try
            {
                project = await TimeSheetContext.Project.Where(x => x.Id == project.Id).Include(x => x.Users).Include(x => x.Activitys).Include(x => x.Logs).SingleOrDefaultAsync();
            }
            catch (Exception e)
            {
                return(false);
            }
            bool hasUsers = false;

            if (project.Users == null)
            {
                return(false);
            }
            if (project.Users.Count > 0)
            {
                hasUsers = true;
            }
            if (hasUsers)
            {
                foreach (Models.ProjectUser user in project.Users)
                {
                    TimeSheetContext.Remove(user);
                }
            }
            bool hasActivity = false;

            if (project.Activitys == null)
            {
                return(false);
            }
            if (project.Activitys.Count > 0)
            {
                hasActivity = true;
            }
            if (hasActivity)
            {
                foreach (Models.Activity activity in project.Activitys)
                {
                    TimeSheetContext.Remove(activity);
                }
            }
            bool hasLog = false;

            if (project.Logs == null)
            {
                return(false);
            }
            if (project.Logs.Count > 0)
            {
                hasLog = true;
            }
            if (hasLog)
            {
                foreach (Models.Log log in project.Logs)
                {
                    TimeSheetContext.Remove(log);
                }
            }
            TimeSheetContext.Remove(project);
            await TimeSheetContext.SaveChangesAsync();

            return(true);
        }