Beispiel #1
0
        public GenericValidator EditCompany(ImporterObject company)
        {
            var gVal = new GenericValidator();

            try
            {
                var appStatus = new ImporterServices().UpdateImporter(company);
                if (appStatus < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = appStatus == -2 ? "Company failed. Please try again." : "Company Information already exists";
                    return(gVal);
                }

                gVal.Code  = appStatus;
                gVal.Error = "Company was successfully updated.";
                return(gVal);
            }
            catch (Exception)
            {
                gVal.Error = "Company processing failed. Please try again later";
                gVal.Code  = -1;
                return(gVal);
            }
        }
Beispiel #2
0
        public long UpdateImporter(ImporterObject importer)
        {
            try
            {
                if (importer == null)
                {
                    return(-2);
                }

                var importerEntity = ModelMapper.Map <ImporterObject, Importer>(importer);
                if (importerEntity == null || importerEntity.Id < 1)
                {
                    return(-2);
                }

                using (var db = new ImportPermitEntities())
                {
                    db.Importers.Attach(importerEntity);
                    db.Entry(importerEntity).State = EntityState.Modified;
                    db.SaveChanges();
                    return(importer.Id);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                return(0);
            }
        }
 public long UpdateImporter(ImporterObject importer)
 {
     try
     {
         return(_importerManager.UpdateImporter(importer));
     }
     catch (Exception ex)
     {
         ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
         return(0);
     }
 }
 public long AddImporterAndPerson(ImporterObject importer, PersonObject person, out long importerId)
 {
     try
     {
         return(_importerManager.AddImporterAndPerson(importer, person, out importerId));
     }
     catch (Exception ex)
     {
         ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
         importerId = 0;
         return(0);
     }
 }
Beispiel #5
0
        public ActionResult AddBank(BankObject bank)
        {
            var gVal = new GenericValidator();

            try
            {
                var validationResult = ValidateBank(bank);

                if (validationResult.Code == 1)
                {
                    return(Json(validationResult, JsonRequestBehavior.AllowGet));
                }

                var company = new ImporterObject
                {
                    Id        = 0,
                    Name      = bank.Name,
                    TIN       = bank.TIN,
                    RCNumber  = bank.RCNumber,
                    IsActive  = true,
                    DateAdded = DateTime.Now.ToString("dd/MM/yyyy")
                };
                var cmStatus = AddCompany(company);
                if (cmStatus.Code < 1)
                {
                    return(Json(cmStatus, JsonRequestBehavior.AllowGet));
                }

                bank.ImporterId = cmStatus.Code;
                var appStatus = new BankServices().AddBank(bank);
                if (appStatus < 1)
                {
                    validationResult.Code  = -1;
                    validationResult.Error = appStatus == -2 ? "Bank processing failed. Please try again." : "Bank Information already exists";
                    return(Json(validationResult, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = appStatus;
                gVal.Error = "Bank was successfully added.";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                gVal.Error = "Bank processing failed. Please try again later";
                gVal.Code  = -1;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #6
0
        public long AddImporter(ImporterObject importer)
        {
            try
            {
                if (importer == null)
                {
                    return(-2);
                }

                var importerEntity = ModelMapper.Map <ImporterObject, Importer>(importer);
                if (string.IsNullOrEmpty(importerEntity.Name))
                {
                    return(-2);
                }
                using (var db = new ImportPermitEntities())
                {
                    long importerId = 0;
                    if (db.Importers.Any())
                    {
                        var existing = db.Importers.OrderByDescending(i => i.Id).Take(1).ToList();
                        if (!existing.Any())
                        {
                            importerId = 1;
                        }
                        else
                        {
                            importerId = existing[0].Id + 1;
                        }
                    }
                    else
                    {
                        importerId = 1;
                    }
                    importerEntity.Id = importerId;
                    var returnStatus = db.Importers.Add(importerEntity);
                    db.SaveChanges();
                    return(returnStatus.Id);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                return(0);
            }
        }
Beispiel #7
0
        public ActionResult EditBank(BankObject bank)
        {
            var gVal = new GenericValidator();

            try
            {
                var stat = ValidateBank(bank);

                if (stat.Code < 1)
                {
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                if (Session["_bank"] == null)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Session has timed out.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var oldbank = Session["_bank"] as BankObject;

                if (oldbank == null)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Session has timed out.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var company = new ImporterObject
                {
                    Id       = oldbank.ImporterId,
                    Name     = bank.Name,
                    TIN      = bank.TIN,
                    RCNumber = bank.RCNumber
                };

                var cmStatus = EditCompany(company);
                if (cmStatus.Code < 1)
                {
                    return(Json(cmStatus, JsonRequestBehavior.AllowGet));
                }

                oldbank.Name = bank.Name;
                oldbank.NotificationEmail = bank.NotificationEmail;
                oldbank.SortCode          = bank.SortCode;
                var docStatus = new BankServices().UpdateBank(oldbank);
                if (docStatus < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = docStatus == -3 ? "Bank already exists." : "Bank information could not be updated. Please try again later";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = oldbank.BankId;
                gVal.Error = "Bank information was successfully updated";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                gVal.Code  = -1;
                gVal.Error = "Bank information could not be updated. Please try again later";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #8
0
        public long AddImporterAndPerson(ImporterObject importer, PersonObject person, out long importerId)
        {
            try
            {
                if (importer == null || person == null)
                {
                    importerId = 0;
                    return(-2);
                }
                long personId;
                using (var db = new ImportPermitEntities())
                {
                    var existings = db.Importers.Where(i => i.Name.ToLower() == importer.Name.ToLower() || i.RCNumber.ToLower().Replace("rc", "") == importer.RCNumber.ToLower().Replace("rc", "") || i.TIN.ToLower().Replace("tin", "") == importer.TIN.ToLower().Replace("tin", "")).ToList();
                    if (existings.Any())
                    {
                        importerId = existings[0].Id;
                    }
                    else
                    {
                        importerId = 0;
                    }
                    var impId          = importerId;
                    var existingPeople = db.People.Where(i => i.FirstName.ToLower() == person.FirstName.ToLower() && i.LastName.ToLower() == person.LastName.ToLower() && i.ImporterId == impId).ToList();

                    if (existingPeople.Any())
                    {
                        personId = existingPeople[0].Id;
                    }
                    else
                    {
                        personId = 0;
                    }

                    if (importerId > 0 && personId > 0)
                    {
                        return(personId);
                    }

                    var importerEntity = ModelMapper.Map <ImporterObject, Importer>(importer);
                    if (importerEntity == null || string.IsNullOrEmpty(importerEntity.Name))
                    {
                        importerId = 0;
                        return(-2);
                    }
                    var personEntity = ModelMapper.Map <PersonObject, Person>(person);
                    if (personEntity == null || string.IsNullOrEmpty(importerEntity.Name))
                    {
                        importerId = 0;
                        return(-2);
                    }

                    if (importerId < 1)
                    {
                        var importerInfo = db.Importers.Add(importerEntity);
                        db.SaveChanges();
                        importerId = importerInfo.Id;
                    }

                    if (personId < 1)
                    {
                        personEntity.ImporterId = importerId;
                        var prs = db.People.Add(personEntity);
                        db.SaveChanges();
                        personId = prs.Id;
                    }

                    return(personId);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                importerId = 0;
                return(0);
            }
        }