Esempio n. 1
0
        public long UpdateFormMDetail(FormMDetailObject formMDetail)
        {
            try
            {
                if (formMDetail == null)
                {
                    return(-2);
                }

                var formMDetailEntity = ModelMapper.Map <FormMDetailObject, FormMDetail>(formMDetail);
                if (formMDetailEntity == null || formMDetailEntity.Id < 1)
                {
                    return(-2);
                }

                using (var db = new ImportPermitEntities())
                {
                    if (db.FormMDetails.Count(m => m.NotificationId == formMDetail.NotificationId && m.Id != formMDetail.Id) > 0)
                    {
                        return(-3);
                    }
                    db.FormMDetails.Attach(formMDetailEntity);
                    db.Entry(formMDetailEntity).State = EntityState.Modified;
                    db.SaveChanges();
                    return(formMDetail.Id);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                return(0);
            }
        }
Esempio n. 2
0
        public long UpdateFormM(FormMDetailObject formM)
        {
            try
            {
                if (formM == null)
                {
                    return(-2);
                }

                var formMEntity = ModelMapper.Map <FormMDetailObject, FormMDetail>(formM);
                if (formMEntity == null)
                {
                    return(-2);
                }

                using (var db = new ImportPermitEntities())
                {
                    var oldFormMs = db.FormMDetails.Where(v => v.Id == formM.Id).ToList();
                    if (!oldFormMs.Any())
                    {
                        return(-2);
                    }

                    var docs = db.Documents.Where(v => v.DocumentId == formM.AttachedDocumentId).ToList();
                    if (!docs.Any())
                    {
                        return(-2);
                    }
                    var doc = docs[0];
                    if (doc.DocumentPath != formM.DocumentPath)
                    {
                        doc.DocumentPath    = formM.DocumentPath;
                        doc.DateUploaded    = formM.DateAttached;
                        db.Entry(doc).State = EntityState.Modified;
                        db.SaveChanges();
                    }

                    var formMDetail = oldFormMs[0];
                    formMDetail.FormMReference     = formM.FormMReference;
                    formMDetail.Quantity           = formM.Quantity;
                    formMDetail.LetterOfCreditNo   = formM.LetterOfCreditNo;
                    formMDetail.AttachedDocumentId = formM.AttachedDocumentId;
                    formMDetail.DateAttached       = formM.DateAttached;
                    db.Entry(formMEntity).State    = EntityState.Modified;
                    db.SaveChanges();
                    return(formMEntity.Id);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                return(0);
            }
        }
Esempio n. 3
0
 public long UpdateFormMDetail(FormMDetailObject formMDetail)
 {
     try
     {
         return(_formMDetailManager.UpdateFormMDetail(formMDetail));
     }
     catch (Exception ex)
     {
         ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
         return(0);
     }
 }
Esempio n. 4
0
 public long AddFormM(FormMDetailObject formM)
 {
     try
     {
         return(_documentManager.AddFormM(formM));
     }
     catch (Exception ex)
     {
         ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
         return(0);
     }
 }
Esempio n. 5
0
        public long AddFormM(FormMDetailObject formM)
        {
            try
            {
                if (formM == null)
                {
                    return(-2);
                }

                var formMEntity = ModelMapper.Map <FormMDetailObject, FormMDetail>(formM);
                if (formMEntity == null)
                {
                    return(-2);
                }

                using (var db = new ImportPermitEntities())
                {
                    var documentEntity = ModelMapper.Map <DocumentObject, Document>(formM.DocumentObject);
                    if (string.IsNullOrEmpty(documentEntity.DocumentPath))
                    {
                        return(-2);
                    }
                    var ntDoc = db.Documents.Add(documentEntity);
                    db.SaveChanges();


                    var app = new NotificationDocument
                    {
                        DocumentId     = ntDoc.DocumentId,
                        NotificationId = formM.DocumentObject.NotificationId,
                        DateAttached   = formM.DocumentObject.DateUploaded,
                        Comment        = formM.DocumentObject.Comment
                    };

                    db.NotificationDocuments.Add(app);
                    db.SaveChanges();

                    formMEntity.AttachedDocumentId = ntDoc.DocumentId;
                    var imApp = db.FormMDetails.Add(formMEntity);
                    db.SaveChanges();

                    return(imApp.Id);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                return(0);
            }
        }