public bool Handle(EditProjectsCommand command)
        {
            using (TransactionScope transaction = new TransactionScope())
            {
                try
                {
                    var project = timeSheetDbContext
                                  .Set <Project>()
                                  .SingleOrDefault(x => x.Id == command.ProjectId);

                    UpdateProject(project, command);

                    if (command.File != null)
                    {
                        var fileId = AddFile(command.File);

                        if (project.IconId.HasValue)
                        {
                            RemoveOldIcon(project.IconId.Value);
                        }

                        project.IconId = fileId;
                        timeSheetDbContext.SaveChanges();
                    }

                    transaction.Complete();
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }
Exemple #2
0
        public bool Handle(UpdateUserProfileCommand command)
        {
            using (TransactionScope transaction = new TransactionScope())
            {
                try
                {
                    var user = manageUsersDbContext
                               .Set <TRUser>()
                               .SingleOrDefault(x => x.Id == command.UserId);

                    var currentAvt = timeSheetDbContext
                                     .Set <File>()
                                     .SingleOrDefault(x => x.Id == user.AvartarId);

                    user.FirstName   = command.FirstName;
                    user.LastName    = command.LastName;
                    user.EnglishName = command.EnglishName;
                    user.Gender      = command.Gender;
                    user.DOB         = command.DOB;
                    user.IdNumber    = command.IdNumber;

                    manageUsersDbContext.SaveChanges();

                    if (command.File != null)
                    {
                        var fileId = AddFile(command.File);
                        if (user.AvartarId != Guid.Empty)
                        {
                            RemoveOldIcon(user.AvartarId);
                        }

                        user.AvartarId = fileId;
                        timeSheetDbContext.SaveChanges();
                        manageUsersDbContext.SaveChanges();
                    }

                    transaction.Complete();
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }
 protected override void HandleCore(AddEquipmentCommand command)
 {
     using (TransactionScope transaction = new TransactionScope())
     {
         var addEquipment = AddEquipment(command);
         if (command.File != null)
         {
             var fileId = AddIcon(command.File);
             addEquipment.ImageId = fileId;
             timesheetReportContext.SaveChanges();
         }
         else
         {
             timesheetReportContext.SaveChanges();
         }
         transaction.Complete();
     }
 }
Exemple #4
0
        public string Handle(DeleteTaskCommand command)
        {
            var task = timeSheetDbContext.Set <WorkTime>().Where(x => x.TimeId == command.TaskId);

            timeSheetDbContext.Set <WorkTime>().RemoveRange(task);
            timeSheetDbContext.SaveChanges();

            return("Add successfully");
        }
Exemple #5
0
        public string Handle(UploadFileCommand command)
        {
            try
            {
                timeSheetDbContext.Set <File>().Add(command.File);
                timeSheetDbContext.SaveChanges();

                return("Success");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
        public string Handle(EditWorkTimeCommand command)
        {
            var workTime = timeSheetDbContext
                           .Set <WorkTime>()
                           .SingleOrDefault(x => x.TimeId == command.Id);

            workTime.Hours     = command.Hours;
            workTime.ProjectId = command.ProjectId;
            workTime.Task      = command.Tasks;

            timeSheetDbContext.SaveChanges();

            return("Edit successfully");
        }
        public bool Handle(AddProjectsCommand command)
        {
            using (TransactionScope transaction = new TransactionScope())
            {
                try
                {
                    var project = AddProject(command);
                    if (command.File != null)
                    {
                        var fileId = AddIcon(command.File);
                        project.IconId = fileId;
                        timeSheetDbContext.SaveChanges();
                    }

                    transaction.Complete();
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }
        public WorkTime Handle(AddWorkTimeCommand command)
        {
            WorkTime worktime = new WorkTime()
            {
                ProjectId  = command.ProjectId,
                Hours      = command.Hours,
                Task       = command.Tasks,
                TimeId     = Guid.NewGuid(),
                Time       = command.AddedDate,
                EmployeeId = command.UserId
            };

            timeSheetDbContext.Set <WorkTime>().Add(worktime);
            timeSheetDbContext.SaveChanges();

            return(worktime);
        }