Пример #1
0
        public void Save(Project project)
        {
            var session = SessionManager.OpenSessionIfRequired(this.sessionFactory);
            using (var transaction = session.BeginTransaction())
            {
                var otherBenefits = new List<OtherBenefit>(project.OtherBenefits);
                project.OtherBenefits.Clear();
                foreach (var item in otherBenefits)
                {
                    project.OtherBenefits.Add(session.Merge(item));
                }

                var tasks = new List<ProjectTask>(project.Tasks);
                project.Tasks.Clear();
                foreach (var item in tasks)
                {
                    project.Tasks.Add(session.Merge(item));
                }

                foreach (var item in project.Hardwares)
                {
                    var hardwareTasks = new List<ProjectHardwareTask>(item.Tasks);
                    item.Tasks.Clear();
                    foreach(var t in hardwareTasks)
                    {
                        item.Tasks.Add(session.Merge(t));
                    }
                }

                session.SaveOrUpdate(project);
                session.Transaction.Commit();
            }
        }
Пример #2
0
 public void Delete(Project project)
 {
     var session = SessionManager.OpenSessionIfRequired(this.sessionFactory);
     using (var transaction = session.BeginTransaction())
     {
         session.Delete(project);
         session.Transaction.Commit();
     }
 }
Пример #3
0
        private ProjectViewModel Map(Project project)
        {
            Mapper.CreateMap<Project, ProjectViewModel>();
            var viewModel = Mapper.Map<Project, ProjectViewModel>(project);

            if (viewModel.StartDate == DateTime.MinValue)
            {
                viewModel.StartDate = DateTime.Now;
            }

            if (viewModel.EndDate == DateTime.MinValue)
            {
                viewModel.EndDate = DateTime.Now;
            }

            if (viewModel.Comment == null || !(viewModel.Comment.StartsWith("{\\rtf") && viewModel.Comment.EndsWith("}")))
                viewModel.Comment = "{\\rtf" + viewModel.Comment + "}";

            viewModel.TotalModules = project.Hardwares.Sum(x => x.Components.Sum(y => y.Quantity * y.Supply.ModuleSize)) +
                project.Supplies.Sum(x => x.Quantity * x.ModuleSize);

            viewModel.ModulesNotInFrame = viewModel.TotalModules - project.Frames.Sum(x => x.Count * x.Size);
            if (viewModel.ModulesNotInFrame < 0)
            {
                viewModel.ModulesNotInFrame = 0;
            }

            viewModel.TotalPrice = 0;
            foreach (var item in project.Supplies)
            {
                viewModel.TotalPrice += item.Quantity * item.Price;
            }

            foreach (var item in project.Hardwares)
            {
                // total price of components
                viewModel.TotalPrice += item.Components.Sum(x => x.Supply.Price * x.Quantity);

                foreach (var task in item.Tasks)
                {
                    double rate = 0.0;
                    if (task.Task != null)
                    {
                        switch (task.HardwareTaskType)
                        {
                            case ProjectHardwareTaskType.DAY:
                                rate = task.Task.DayRate;
                                break;
                            case ProjectHardwareTaskType.SHORT_NIGHT:
                                rate = task.Task.ShortNightRate;
                                break;
                            case ProjectHardwareTaskType.LONG_NIGHT:
                                rate = task.Task.LongNightRate;
                                break;
                            default:
                                throw new ArgumentOutOfRangeException();
                        }
                    }
                    viewModel.TotalPrice += rate * task.Value;
                    viewModel.TotalDays += task.Value;
                }
            }

            if (viewModel.OtherBenefits == null)
            {
                viewModel.OtherBenefits = new List<OtherBenefit>();
            }

            viewModel.TotalPrice += viewModel.OtherBenefits.Sum(x => x.Hours * x.CostRate);
            viewModel.TotalDays += viewModel.OtherBenefits.Sum(x => x.Hours);

            return viewModel;
        }