コード例 #1
0
        public long UpdateAccountType(AccountTypeObject accountType)
        {
            try
            {
                if (accountType == null)
                {
                    return(-2);
                }

                using (var db = new ImportPermitEntities())
                {
                    if (db.AccountTypes.Count(g => g.Name.ToLower().Trim().Replace(" ", "") == accountType.Name.ToLower().Trim().Replace(" ", "") && g.AccountTypeId != accountType.AccountTypeId) > 0)
                    {
                        return(-3);
                    }
                    var accountTypeEntity = ModelMapper.Map <AccountTypeObject, AccountType>(accountType);
                    if (accountTypeEntity == null || accountTypeEntity.AccountTypeId < 1)
                    {
                        return(-2);
                    }
                    db.AccountTypes.Attach(accountTypeEntity);
                    db.Entry(accountTypeEntity).State = EntityState.Modified;
                    db.SaveChanges();
                    return(accountType.AccountTypeId);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                return(0);
            }
        }
コード例 #2
0
        public long AddAccountType(AccountTypeObject accountType)
        {
            try
            {
                if (accountType == null)
                {
                    return(-2);
                }

                using (var db = new ImportPermitEntities())
                {
                    if (db.AccountTypes.Count(g => g.Name.ToLower().Trim().Replace(" ", "") == accountType.Name.ToLower().Trim().Replace(" ", "")) > 0)
                    {
                        return(-3);
                    }
                    var accountTypeEntity = ModelMapper.Map <AccountTypeObject, AccountType>(accountType);
                    if (accountTypeEntity == null || string.IsNullOrEmpty(accountTypeEntity.Name))
                    {
                        return(-2);
                    }
                    var returnStatus = db.AccountTypes.Add(accountTypeEntity);
                    db.SaveChanges();
                    return(returnStatus.AccountTypeId);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                return(0);
            }
        }
コード例 #3
0
        public ActionResult EditAccountType(AccountTypeObject accountType)
        {
            var gVal = new GenericValidator();

            try
            {
                if (!ModelState.IsValid)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Plese provide all required fields and try again.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var stat = ValidateAccountType(accountType);

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

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

                var oldaccountType = Session["_accountType"] as AccountTypeObject;

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

                oldaccountType.Name        = accountType.Name.Trim();
                oldaccountType.Description = accountType.Description;
                var docStatus = new AccountTypeServices().UpdateAccountType(oldaccountType);
                if (docStatus < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = docStatus == -3 ? "Account Type already exists." : "Account Type information could not be updated. Please try again later";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = oldaccountType.AccountTypeId;
                gVal.Error = "Account Type information was successfully updated";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                gVal.Code  = -1;
                gVal.Error = "Account Type information could not be updated. Please try again later";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #4
0
 public long AddAccountType(AccountTypeObject accountType)
 {
     try
     {
         return _accountTypeManager.AddAccountType(accountType);
     }
     catch (Exception ex)
     {
         ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
         return 0;
     }
 }
コード例 #5
0
        public ActionResult AddAccountType(AccountTypeObject accountType)
        {
            var gVal = new GenericValidator();

            try
            {
                if (!ModelState.IsValid)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Plese provide all required fields and try again.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

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

                var validationResult = ValidateAccountType(accountType);

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

                var appStatus = new AccountTypeServices().AddAccountType(accountType);
                if (appStatus < 1)
                {
                    validationResult.Code  = -1;
                    validationResult.Error = appStatus == -2 ? "AccountType upload failed. Please try again." : "The Account Type Information already exists";
                    return(Json(validationResult, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = appStatus;
                gVal.Error = "Account Type was successfully added.";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                gVal.Error = "Account Type processing failed. Please try again later";
                gVal.Code  = -1;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #6
0
        private GenericValidator ValidateAccountType(AccountTypeObject accountType)
        {
            var gVal = new GenericValidator();

            try
            {
                if (string.IsNullOrEmpty(accountType.Name))
                {
                    gVal.Code  = -1;
                    gVal.Error = "Please provide Account Type.";
                    return(gVal);
                }

                gVal.Code = 5;
                return(gVal);
            }
            catch (Exception)
            {
                gVal.Code  = -1;
                gVal.Error = "Account Type Validation failed. Please provide all required fields and try again.";
                return(gVal);
            }
        }