Exemplo n.º 1
0
        private GenericValidator ValidatePermit(PermitObject permit)
        {
            var gVal = new GenericValidator();

            try
            {
                if (permit.Id < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Please select a Permit.";
                    return(gVal);
                }



                gVal.Code = 5;
                return(gVal);
            }
            catch (Exception)
            {
                gVal.Code  = -1;
                gVal.Error = "Permit Validation failed. Please provide all required fields and try again.";
                return(gVal);
            }
        }
Exemplo n.º 2
0
        public long UpdatePermit(PermitObject permit)
        {
            try
            {
                if (permit == null)
                {
                    return(-2);
                }

                var permitEntity = ModelMapper.Map <PermitObject, Permit>(permit);
                if (permitEntity == null || permitEntity.Id < 1)
                {
                    return(-2);
                }

                using (var db = new ImportPermitEntities())
                {
                    db.Permits.Attach(permitEntity);
                    db.Entry(permitEntity).State = EntityState.Modified;
                    db.SaveChanges();
                    return(permit.Id);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                return(0);
            }
        }
        private PermitObject ProcessRecord(DataRowView dv, ref string msg)
        {
            if (dv == null)
            {
                return(null);
            }
            try
            {
                var permit = new PermitObject();

                var companyName = dv.Row["Company"].ToString().Trim();

                if (string.IsNullOrEmpty(companyName))
                {
                    msg = "Company Name is empty.";
                    return(null);
                }

                permit.CompanyName = companyName;

                var refCode = dv.Row["Reference_Number"].ToString().Trim();
                if (string.IsNullOrEmpty(refCode))
                {
                    msg = "License Number is empty.";
                    return(null);
                }

                var issueDate = dv.Row["Issue_Date"].ToString().Trim();
                if (string.IsNullOrEmpty(issueDate))
                {
                    msg = "Issue Date is empty.";
                    return(null);
                }

                var expiryDate = dv.Row["Expiry_Date"].ToString().Trim();
                if (string.IsNullOrEmpty(expiryDate))
                {
                    msg = "Expiry Date is empty.";
                    return(null);
                }

                permit.ExpiryDate       = DateTime.Parse(expiryDate);
                permit.IssueDate        = DateTime.Parse(issueDate);
                permit.PermitStatus     = 2;
                permit.PermitValue      = refCode;
                permit.PermitNo         = 0;
                permit.ImporterId       = 0;
                permit.DateAdded        = DateTime.Now;
                permit.QuantityImported = 0;
                permit.file             = "";
                return(permit);
            }
            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                return(null);
            }
        }
Exemplo n.º 4
0
 public long UpdatePermit(PermitObject permit)
 {
     try
     {
         return(_permitManager.UpdatePermit(permit));
     }
     catch (Exception ex)
     {
         ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
         return(0);
     }
 }
Exemplo n.º 5
0
        public ActionResult EditPermit(PermitObject permit)
        {
            var gVal = new GenericValidator();

            try
            {
                var stat = ValidatePermit(permit);

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

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

                var oldpermit = Session["_permit"] as PermitObject;

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

                oldpermit.Id = permit.Id;

                var docPermitStatus = new PermitServices().UpdatePermit(oldpermit);
                if (docPermitStatus < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = docPermitStatus == -3 ? "Permit already exists." : "Permit information could not be updated. Please try again later";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = oldpermit.Id;
                gVal.Error = "Permit information was successfully updated";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                gVal.Code  = -1;
                gVal.Error = "Permit information could not be updated. Please try again later";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 6
0
        public long AddPermit(PermitObject permit)
        {
            try
            {
                if (permit == null)
                {
                    return(-2);
                }

                var permitEntity = ModelMapper.Map <PermitObject, Permit>(permit);

                if (permitEntity == null)
                {
                    return(-2);
                }

                using (var db = new ImportPermitEntities())
                {
                    var stopDate = DateTime.Parse("2015-07-31");
                    if (DateTime.Today <= stopDate)
                    {
                        var existingSimilarPermits = db.Permits.Where(m => m.PermitValue.Trim() == permit.PermitValue.Trim() && m.ImporterId == permit.ImporterId).ToList();

                        if (existingSimilarPermits.Any())
                        {
                            return(existingSimilarPermits[0].Id);
                        }

                        var returnStatus = db.Permits.Add(permitEntity);
                        db.SaveChanges();
                        return(returnStatus.Id);
                    }
                    else
                    {
                        var returnStatus = db.Permits.Add(permitEntity);
                        db.SaveChanges();
                        return(returnStatus.Id);
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                return(0);
            }
        }
Exemplo n.º 7
0
        public ActionResult AddPermit(PermitObject permit)
        {
            var gVal = new GenericValidator();

            try
            {
                var importerInfo = GetLoggedOnUserInfo();
                if (importerInfo.Id < 1)
                {
                    gVal.Error = "Your session has timed out";
                    gVal.Code  = -1;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var validationResult = ValidatePermit(permit);

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

                var appPermitStatus = new PermitServices().AddPermit(permit);
                if (appPermitStatus < 1)
                {
                    validationResult.Code  = -1;
                    validationResult.Error = appPermitStatus == -2 ? "Permit upload failed. Please try again." : "The Permit Information already exists";
                    return(Json(validationResult, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = appPermitStatus;
                gVal.Error = "Permit was successfully added.";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                gVal.Error = "Permit processing failed. Please try again later";
                gVal.Code  = -1;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 8
0
        public long AddBulkPermit(PermitObject permit)
        {
            try
            {
                var permitEntity = ModelMapper.Map <PermitObject, Permit>(permit);

                if (permitEntity == null)
                {
                    return(-2);
                }

                using (var db = new ImportPermitEntities())
                {
                    int permid;

                    var permits = db.Permits.OrderByDescending(l => l.PermitNo).Take(1);

                    if (permits.Any())
                    {
                        permid = permits.First().PermitNo + 1;
                    }
                    else
                    {
                        permid = 1;
                    }
                    var permNum = "";
                    var count   = permid.ToString().Length;
                    if (count == 1)
                    {
                        permNum = "00000" + permid;
                    }
                    else if (count == 2)
                    {
                        permNum = "0000" + permid;
                    }
                    else if (count == 3)
                    {
                        permNum = "000" + permid;
                    }
                    else if (count == 4)
                    {
                        permNum = "00" + permid;
                    }
                    else if (count == 5)
                    {
                        permNum = "0" + permid;
                    }
                    else if (count >= 6)
                    {
                        permNum = permid.ToString();
                    }

                    var year = DateTime.Now.Year;

                    var perm = new Permit
                    {
                        IssueDate = DateTime.Now,
                        PermitNo  = permid,

                        PermitValue = "DPR/PPIPS/RC" + year + "/" + permNum,
                        DateAdded   = DateTime.Now
                    };

                    perm.PermitStatus = (int)PermitStatusEnum.Active;
                    db.Permits.Add(perm);
                    db.SaveChanges();
                    return(5);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                return(0);
            }
        }
        public ActionResult VerifyPermit(string permNo)
        {
            var perm = new PermitObject();

            try
            {
                if (String.IsNullOrEmpty(permNo))
                {
                    perm.IsNull = true;
                    return(Json(perm, JsonRequestBehavior.AllowGet));
                }



                using (var db = new ImportPermitEntities())
                {
                    var dat   = DateTime.Now;
                    var check = db.Permits.Where(c => c.PermitValue.Equals(permNo)).ToList();
                    if (check.Any())
                    {
                        var permdate = check[0].ExpiryDate;

                        var permId  = check[0].Id;
                        var permApp = db.PermitApplications.Where(p => p.PermitId == permId).ToList();
                        if (permApp.Any())
                        {
                            var appId = permApp[0].ApplicationId;
                            var app   = db.Applications.Where(a => a.Id == appId).ToList();
                            if (app.Any())
                            {
                                perm.CompanyName = app[0].Importer.Name;
                                var permit = db.Permits.Where(m => m.Id == permId).ToList();

                                if (permit.Any())
                                {
                                    perm.IssueDateStr  = permit[0].IssueDate.ToString();
                                    perm.ExpiryDateStr = permit[0].ExpiryDate.ToString();
                                    perm.QuantityStr   = permit[0].QuantityImported.ToString();
                                    if (dat > permdate)
                                    {
                                        perm.IsExpired = true;
                                        return(Json(perm, JsonRequestBehavior.AllowGet));
                                    }
                                    perm.IsValid = true;
                                    return(Json(perm, JsonRequestBehavior.AllowGet));
                                }
                            }
                            perm.NoEmployee = true;
                        }

                        perm.NoEmployee = true;
                    }


                    perm.NoEmployee = true;
                    return(Json(perm, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                perm.IsError = true;
                return(Json(perm, JsonRequestBehavior.AllowGet));
            }
        }