Esempio n. 1
0
        public Int64 AddDate(Objects.Date date)
        {
            IUnitOfWork        unitOfWork = SessionFactory.GetUnitOfWork;
            IRepository <Date> repository = new Repositor <Date>(unitOfWork);

            try
            {
                ObjectValidator.IsValid(date);
                Date d = new Date();
                d.DateDate         = date.DateContent;
                d.DateIsNight      = date.IsNight;
                d.DateIsClosed     = false;
                d.DateDetachmentID = date.DetachmentID;
                d.DateDescription  = String.IsNullOrWhiteSpace(date.Description) ? null : date.Description;
                unitOfWork.BeginTransaction();
                var de = repository.Find(c => c.DateDate.Date >= date.DateContent.Date && c.DateDetachmentID == date.DetachmentID).ToList();
                if (de != null)
                {
                    if (de.Any(c => c.DateDate.Date > date.DateContent.Date) || de.Any(c => c.DateDate.Date == date.DateContent.Date && c.DateIsNight == true))
                    {
                        throw new FormatException("Není možné vytvářet směnu zpětně!");
                    }
                }
                repository.Add(d);
                unitOfWork.CommitTransaction();
                return(d.DateID);
            }
            catch (Exception e)
            {
                unitOfWork.RollbackTransaction();
                throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e));
            }
        }
Esempio n. 2
0
        public void UpdateDate(Objects.Date date)
        {
            IUnitOfWork        unitOfWork = SessionFactory.GetUnitOfWork;
            IRepository <Date> repository = new Repositor <Date>(unitOfWork);

            try
            {
                ObjectValidator.IsValid(date);
                unitOfWork.BeginTransaction();
                var d = repository.Single(c => c.DateID == date.ID);
                d.DateIsClosed    = date.IsClosed;
                d.DateDescription = String.IsNullOrWhiteSpace(date.Description) ? null : date.Description;
                repository.Update(d);
                unitOfWork.CommitTransaction();
            }
            catch (Exception e)
            {
                unitOfWork.RollbackTransaction();
                throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e));
            }
        }