Exemplo n.º 1
0
        public TemporaryDto SaveTemp(TemporaryDto item, DateTime expectedDate, Login CurrentUser)
        {
            TRA_TEMPORARY model;

            if (item == null)
            {
                throw new Exception("Invalid Data Entry");
            }

            try
            {
                if (item.TRA_TEMPORARY_ID > 0)
                {
                    //update
                    model = _temporaryService.GetTemporaryById(item.TRA_TEMPORARY_ID);

                    if (model == null)
                    {
                        throw new BLLException(ExceptionCodes.BLLExceptions.DataNotFound);
                    }

                    Mapper.Map <TemporaryDto, TRA_TEMPORARY>(item, model);
                }
                else
                {
                    var inputDoc = new GenerateDocNumberInput();
                    inputDoc.Month   = DateTime.Now.Month;
                    inputDoc.Year    = DateTime.Now.Year;
                    inputDoc.DocType = (int)Enums.DocumentType.TMP;

                    item.DOCUMENT_NUMBER_TEMP = _docNumberService.GenerateNumber(inputDoc);
                    item.IS_ACTIVE            = true;

                    model = Mapper.Map <TRA_TEMPORARY>(item);
                }

                _temporaryService.saveTemporary(model, CurrentUser);
                var data = _CrfService.GetByNumber(item.DOCUMENT_NUMBER_RELATED);
                data.EXPECTED_DATE = expectedDate;
                _CrfService.SaveCrf(data, null);
                _uow.SaveChanges();
            }
            catch (Exception exception)
            {
                throw exception;
            }

            return(Mapper.Map <TemporaryDto>(model));
        }
Exemplo n.º 2
0
        public TemporaryDto Save(TemporaryDto item, Login userLogin)
        {
            TRA_TEMPORARY model;

            if (item == null)
            {
                throw new Exception("Invalid Data Entry");
            }

            try
            {
                bool changed = false;

                if (item.TRA_TEMPORARY_ID > 0)
                {
                    //update
                    model = _TemporaryService.GetTemporaryById(item.TRA_TEMPORARY_ID);

                    if (model == null)
                    {
                        throw new BLLException(ExceptionCodes.BLLExceptions.DataNotFound);
                    }

                    Mapper.Map <TemporaryDto, TRA_TEMPORARY>(item, model);

                    changed = true;
                }
                else
                {
                    var inputDoc = new GenerateDocNumberInput();
                    inputDoc.Month   = DateTime.Now.Month;
                    inputDoc.Year    = DateTime.Now.Year;
                    inputDoc.DocType = (int)Enums.DocumentType.TMP;

                    item.DOCUMENT_NUMBER_TEMP = _docNumberService.GenerateNumber(inputDoc);
                    item.IS_ACTIVE            = true;
                    item.EMPLOYEE_ID_CREATOR  = userLogin.EMPLOYEE_ID;

                    model = Mapper.Map <TRA_TEMPORARY>(item);
                }

                _TemporaryService.saveTemporary(model, userLogin);
                _uow.SaveChanges();

                //set workflow history
                var input = new TempWorkflowDocumentInput()
                {
                    DocumentId = model.TRA_TEMPORARY_ID,
                    ActionType = Enums.ActionType.Modified,
                    UserId     = userLogin.USER_ID
                };

                if (changed)
                {
                    AddWorkflowHistory(input);
                }
                _uow.SaveChanges();
            }
            catch (Exception exception)
            {
                throw exception;
            }

            return(Mapper.Map <TemporaryDto>(model));
        }