コード例 #1
0
        public JsonResult AddGoodNews(AddGoodNewsViewModel model)
        {
            using (var db = new TourEntities())
            {
                if (ModelState.IsValid)
                {
                    var formsAuthentication = HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName] != null
                    ? FormsAuthentication.Decrypt(
                        HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName].Value)
                    : null;

                    string imageName = System.IO.Path.GetFileName(model.PhotoPath.FileName);
                    imageName = MetadataServices.GetDateTimeWithoutSlash() + "-" + imageName;
                    string physicalPath = Server.MapPath("~/Image/GoodNews/" + imageName);
                    model.PhotoPath.SaveAs(physicalPath);

                    var goodNews = new GoodNews()
                    {
                        GoodNewsTitle = model.GoodNewsTitle,
                        PhotoPath     = imageName,
                        Description   = model.Description == null ? "" : model.Description,
                        CreatedBy     = MetadataServices.GetCurrentUser().Username,
                        CreatedAt     = MetadataServices.GetCurrentDate(),
                        UpdatedBy     = MetadataServices.GetCurrentUser().Username,
                        UpdatedAt     = MetadataServices.GetCurrentDate(),
                    };
                    db.GoodNews.Add(goodNews);
                    db.SaveChanges();
                }
                return(Json(new { }, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #2
0
        public ActionResult UpdateAgentProfile()
        {
            using (var db = new TourEntities())
            {
                int userId = MetadataServices.GetCurrentUser().UserId;

                var agent = db.Agent.Where(x => x.UserId == userId).FirstOrDefault();
                if (agent == null)
                {
                    return(new HttpNotFoundResult("Agent not found"));
                }
                var user = db.User.Where(e => e.UserId == agent.UserId).FirstOrDefault();

                return(View(new EditAgentProfileViewModel()
                {
                    AgentId = agent.AgentId,
                    EmailAddress = user.EmailAddress,
                    DOB = agent.DOB,
                    DOBString = agent.DOB.ToString("yyyy-MM-dd HH:mm"),
                    AgentName = agent.AgentName,
                    BankName = agent.BankName,
                    BankAccountNumber = agent.BankAccountNumber,
                    Address = agent.Address,
                    NRIC = agent.NRIC,
                    PhoneNumber = agent.PhoneNumber,
                    UserId = user.UserId
                }));
            }
        }
コード例 #3
0
        public JsonResult AddProductRedeem(AddProductRedeemViewModel model)
        {
            using (var db = new TourEntities())
            {
                if (ModelState.IsValid)
                {
                    var formsAuthentication = HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName] != null
                    ? FormsAuthentication.Decrypt(
                        HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName].Value)
                    : null;

                    string imageName = System.IO.Path.GetFileName(model.ImagePath.FileName);
                    imageName = MetadataServices.GetDateTimeWithoutSlash() + "-" + imageName;
                    string physicalPath = Server.MapPath("~/Image/Product/" + imageName);
                    model.ImagePath.SaveAs(physicalPath);

                    var newProductRedeemViewModel = new ProductRedeem()
                    {
                        ProductRedeemName = model.ProductRedeemName,
                        RedeemPoint       = model.RedeemPoint,
                        Stock             = model.Stock,
                        ImagePath         = imageName,
                        CreatedBy         = MetadataServices.GetCurrentUser().Username,
                        CreatedAt         = MetadataServices.GetCurrentDate(),
                        UpdatedBy         = MetadataServices.GetCurrentUser().Username,
                        UpdatedAt         = MetadataServices.GetCurrentDate()
                    };
                    db.ProductRedeem.Add(newProductRedeemViewModel);
                    db.SaveChanges();
                }
                return(Json(new { }, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #4
0
        public async System.Threading.Tasks.Task <JsonResult> SendBirthdayWishes()
        {
            try
            {
                using (var db = new TourEntities())
                {
                    var currentDate      = MetadataServices.GetCurrentDate();
                    var customerBirthday = db.Customer.Where(e => e.DateOfBirth.Month.Equals(currentDate.Month) && e.DateOfBirth.Day.Equals(currentDate.Day)).ToList();
                    foreach (var customer in customerBirthday)
                    {
                        var user = db.User.FirstOrDefault(e => e.UserId == customer.UserId);
                        if (user == null)
                        {
                            continue;
                        }
                        MetadataServices.SendWhatsappMessage("Hi " + customer.CustomerName + ", Happy Birthday to you.", customer.PhoneNumber);;
                        await MetadataServices.SendEmail(user.EmailAddress, "Wishes from EnjoyOurTour", "Hi " + customer.CustomerName + ", <br/><br/>Happy Birthday to you!");
                    }
                    return(Json(new { status = "success" }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { status = "failed" }, JsonRequestBehavior.AllowGet));

                throw;
            }
        }
コード例 #5
0
        public ActionResult ViewDetail()
        {
            using (var db = new TourEntities())
            {
                User user = MetadataServices.GetCurrentUser();
                var  role = db.Role.FirstOrDefault(e => e.RoleId.Equals(user.RoleId));


                if (role.RoleName == TourRole.Admin)
                {
                    return(RedirectToAction("Index", "Admin"));
                }
                else if (role.RoleName == TourRole.Superadmin)
                {
                    return(RedirectToAction("Index", "Admin"));
                }
                else if (role.RoleName == TourRole.Agent)
                {
                    return(RedirectToAction("AgentTransaction", "Agent"));
                }
                else if (role.RoleName == TourRole.Customer)
                {
                    return(RedirectToAction("TravelPromotion", "Customer"));
                }
                else
                {
                    return(RedirectToAction("Login", "Account"));
                }
            }
        }
コード例 #6
0
        public virtual InternalEntityEntry PrepareToSave()
        {
            if (EntityState == EntityState.Added)
            {
                var setProperty = EntityType.GetProperties().FirstOrDefault(p => p.IsReadOnlyBeforeSave && !IsTemporaryOrDefault(p));
                if (setProperty != null)
                {
                    throw new InvalidOperationException(CoreStrings.PropertyReadOnlyBeforeSave(setProperty.Name, EntityType.DisplayName()));
                }
            }
            else if (EntityState == EntityState.Modified)
            {
                var modifiedProperty = EntityType.GetProperties().FirstOrDefault(p => p.IsReadOnlyAfterSave && IsModified(p));
                if (modifiedProperty != null)
                {
                    throw new InvalidOperationException(CoreStrings.PropertyReadOnlyAfterSave(modifiedProperty.Name, EntityType.DisplayName()));
                }
            }

            var properties = FindPropertiesThatMayGetStoreValue();

            if (properties.Any())
            {
                AddSidecar(MetadataServices.CreateStoreGeneratedValues(this, properties));
            }

            return(this);
        }
コード例 #7
0
        public JsonResult AddMerchantPromotion(AddMerchantPromotionViewModel model)
        {
            using (var db = new TourEntities())
            {
                if (ModelState.IsValid)
                {
                    var formsAuthentication = HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName] != null
                    ? FormsAuthentication.Decrypt(
                        HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName].Value)
                    : null;

                    var newMerchantPromotion = new MerchantPromotion()
                    {
                        MechantId = model.MerchantId,
                        MerchantPromotionDetail = model.MerchantPromotionDetail,
                        CreatedBy = MetadataServices.GetCurrentUser().Username,
                        CreatedAt = MetadataServices.GetCurrentDate(),
                        UpdatedBy = MetadataServices.GetCurrentUser().Username,
                        UpdatedAt = MetadataServices.GetCurrentDate()
                    };
                    db.MerchantPromotion.Add(newMerchantPromotion);
                    db.SaveChanges();
                }
                return(Json(new { }, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #8
0
        public JsonResult EditMerchantPromotion(AddMerchantPromotionViewModel model)
        {
            try
            {
                using (var db = new TourEntities())
                {
                    var formsAuthentication = HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName] != null
                  ? FormsAuthentication.Decrypt(
                        HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName].Value)
                  : null;

                    if (ModelState.IsValid)
                    {
                        var merchantPromo = db.MerchantPromotion.Find(model.MerchantPromotionId);

                        merchantPromo.MechantId = model.MerchantId;
                        merchantPromo.MerchantPromotionDetail = model.MerchantPromotionDetail;
                        merchantPromo.UpdatedBy = MetadataServices.GetCurrentUser().Username;
                        merchantPromo.UpdatedAt = MetadataServices.GetCurrentDate();

                        db.SaveChanges();
                    }
                    return(Json(new { }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #9
0
        public JsonResult RedeemCoupon(RedeemCouponViewModel model)
        {
            using (var db = new TourEntities())
            {
                var couponTransaction = db.RedeemCoupon.Where(x => x.CouponCode == model.CouponCode).FirstOrDefault();

                if (couponTransaction != null)
                {
                    ModelState.AddModelError("CouponCode", "Coupon Code had been redeem before.");
                }

                if (ModelState.IsValid)
                {
                    string       imageName = "";
                    RedeemCoupon newCoupon = new RedeemCoupon();

                    if (model.Image != null)
                    {
                        imageName = System.IO.Path.GetFileName(model.Image.FileName);
                        imageName = MetadataServices.GetDateTimeWithoutSlash() + "-" + imageName;
                        string physicalPath = Server.MapPath("~/Image/RedeemCoupon/" + imageName);
                        model.Image.SaveAs(physicalPath);
                    }

                    var currentUser = MetadataServices.GetCurrentUser();

                    var customer = db.Customer.Where(x => x.UserId == currentUser.UserId).FirstOrDefault();

                    newCoupon.CouponCode        = model.CouponCode;
                    newCoupon.TVRAmount         = model.Amount;
                    newCoupon.ImageProof        = imageName;
                    newCoupon.CustomerId        = customer.CustomerId;
                    newCoupon.CreatedBy         = currentUser.Username;
                    newCoupon.CreatedAt         = DateTime.Now;
                    newCoupon.UpdatedAt         = DateTime.Now;
                    newCoupon.UpdatedBy         = currentUser.Username;
                    newCoupon.TransactionStatus = (int)EnjoyOurTour.Helpers.TransactionStatus.Pending;

                    db.RedeemCoupon.Add(newCoupon);
                    db.SaveChanges();

                    return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    List <string> errors = new List <string>();

                    foreach (ModelState modelState in ViewData.ModelState.Values)
                    {
                        foreach (ModelError error in modelState.Errors)
                        {
                            errors.Add(string.IsNullOrEmpty(error.ErrorMessage) ? error.Exception.ToString() : error.ErrorMessage);
                        }
                    }
                    return(Json(new { success = false, errors = errors }, JsonRequestBehavior.AllowGet));
                }
            }
        }
コード例 #10
0
        public virtual bool PrepareToSave()
        {
            if (HasConceptualNull)
            {
                var fks = EntityType.GetForeignKeys()
                          .Where(fk => fk.Properties
                                 .Any(p => _stateData.IsPropertyFlagged(p.Index, PropertyFlag.Null)))
                          .ToList();

                if (fks.Any(fk => fk.DeleteBehavior == DeleteBehavior.Cascade))
                {
                    SetEntityState(EntityState == EntityState.Added
                        ? EntityState.Detached
                        : EntityState.Deleted);
                }
                else if (fks.Any())
                {
                    throw new InvalidOperationException(CoreStrings.RelationshipConceptualNull(
                                                            fks.First().PrincipalEntityType.DisplayName(),
                                                            EntityType.DisplayName()));
                }
                else
                {
                    throw new InvalidOperationException(CoreStrings.PropertyConceptualNull(
                                                            EntityType.GetProperties().First(p => _stateData.IsPropertyFlagged(p.Index, PropertyFlag.Null)).Name,
                                                            EntityType.DisplayName()));
                }
            }

            if (EntityState == EntityState.Added)
            {
                var setProperty = EntityType.GetProperties().FirstOrDefault(p => p.IsReadOnlyBeforeSave && !IsTemporaryOrSentinel(p));
                if (setProperty != null)
                {
                    throw new InvalidOperationException(CoreStrings.PropertyReadOnlyBeforeSave(setProperty.Name, EntityType.DisplayName()));
                }
            }
            else if (EntityState == EntityState.Modified)
            {
                var modifiedProperty = EntityType.GetProperties().FirstOrDefault(p => p.IsReadOnlyAfterSave && IsPropertyModified(p));
                if (modifiedProperty != null)
                {
                    throw new InvalidOperationException(CoreStrings.PropertyReadOnlyAfterSave(modifiedProperty.Name, EntityType.DisplayName()));
                }
            }

            var properties = MayGetStoreValue();

            if (properties.Any())
            {
                AddSidecar(MetadataServices.CreateStoreGeneratedValues(this, properties));
            }

            return(EntityState != EntityState.Detached &&
                   EntityState != EntityState.Unchanged);
        }
コード例 #11
0
        private object[] ExtractShadowValues(IValueReader valueReader)
        {
            var shadowValues = new object[EntityType.ShadowPropertyCount()];

            foreach (var property in EntityType.GetProperties().Where(property => property.IsShadowProperty))
            {
                shadowValues[property.GetShadowIndex()] = MetadataServices.ReadValueFromReader(valueReader, property);
            }

            return(shadowValues);
        }
コード例 #12
0
        public JsonResult EditTravelPromotion(TravelPromotionViewModel model)
        {
            try
            {
                using (var db = new TourEntities())
                {
                    if (ModelState.IsValid)
                    {
                        var formsAuthentication = HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName] != null
                        ? FormsAuthentication.Decrypt(
                            HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName].Value)
                        : null;

                        TravelPromotion travelPromotion = db.TravelPromotion.Where(e => e.TravelPromotionId == model.TravelPromotionId).FirstOrDefault();

                        if (model.Description == null)
                        {
                            travelPromotion.Description = "";
                        }
                        else
                        {
                            travelPromotion.Description = model.Description;
                        }


                        if (model.Image != null)
                        {
                            FileInfo path = new FileInfo(Server.MapPath("~/Image/TravelPromotionImage/" + travelPromotion.PhotoPath));
                            path.Delete();

                            string imageName = System.IO.Path.GetFileName(model.Image.FileName);
                            imageName = MetadataServices.GetDateTimeWithoutSlash() + "-" + imageName;
                            string physicalPath = Server.MapPath("~/Image/TravelPromotionImage/" + imageName);
                            model.Image.SaveAs(physicalPath);
                            travelPromotion.PhotoPath = imageName;
                        }

                        travelPromotion.TravelPromotionTitle = model.TravelPromotionTitle;
                        travelPromotion.UpdatedAt            = MetadataServices.GetCurrentDate();
                        travelPromotion.UpdatedBy            = MetadataServices.GetCurrentUser().Username;
                        db.SaveChanges();
                    }
                    return(Json(new { }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #13
0
        public JsonResult EditMerchant(AddMerchantViewModel model)
        {
            try
            {
                using (var db = new TourEntities())
                {
                    var formsAuthentication = HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName] != null
                  ? FormsAuthentication.Decrypt(
                        HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName].Value)
                  : null;

                    if (ModelState.IsValid)
                    {
                        var merchant = db.Merchant.Find(model.MerchantId);

                        if (model.MerchantLogoPath != null)
                        {
                            FileInfo path = new FileInfo(Server.MapPath("~/Image/Merchant/" + merchant.MerchantLogoPath));
                            path.Delete();

                            string imageName = System.IO.Path.GetFileName(model.MerchantLogoPath.FileName);
                            imageName = MetadataServices.GetDateTimeWithoutSlash() + "-" + imageName;
                            string physicalPath = Server.MapPath("~/Image/Merchant/" + imageName);
                            model.MerchantLogoPath.SaveAs(physicalPath);

                            merchant.MerchantLogoPath = imageName;
                        }

                        merchant.MerchantId           = model.MerchantId;
                        merchant.MerchantName         = model.MerchantName;
                        merchant.MerchantRegisterCode = model.MerchantRegisterCode;
                        merchant.MerchantPhoneNumber  = model.MerchantPhoneNumber;
                        merchant.MerchantAddress      = model.MerchantAddress;
                        merchant.MerchantCategoryId   = model.GetMerchantCategoryId;
                        merchant.MerchantJoinDate     = model.MerchantJoinDate;
                        merchant.UpdatedBy            = MetadataServices.GetCurrentUser().Username;
                        merchant.UpdatedAt            = MetadataServices.GetCurrentDate();

                        db.SaveChanges();
                    }
                    return(Json(new { }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #14
0
        public ActionResult TopUpCustomer()
        {
            using (var db = new TourEntities())
            {
                TopUpViewModel topUpViewModel = new TopUpViewModel();
                List <string>  topUpAmount    = new List <string>();

                int?minTopUpAmount = db.SystemSetting.OrderByDescending(x => x.CreadtedDate).FirstOrDefault().MinAmount;

                if (minTopUpAmount != null)
                {
                    topUpAmount.Add(minTopUpAmount.ToString());

                    for (int i = 1; i <= 4; i++)
                    {
                        minTopUpAmount += minTopUpAmount;
                        topUpAmount.Add(minTopUpAmount.ToString());
                    }

                    topUpAmount.Add("Other");
                }

                topUpViewModel.TopUpAmount = topUpAmount.ToList().Select(e => new SelectListItem()
                {
                    Text  = e.ToString(),
                    Value = e.ToString(),
                }).ToList();

                User user = MetadataServices.GetCurrentUser();

                var customer_Agent = db.User_Customer_Adgent.Where(x => x.UserId == user.UserId).FirstOrDefault();

                topUpViewModel.UserId          = user.UserId;
                topUpViewModel.AgentCode       = customer_Agent.AgentCode;
                topUpViewModel.AgentName       = customer_Agent.AgentName;
                topUpViewModel.AvailableAmount = customer_Agent.AvailableAmount;
                topUpViewModel.AvailableTVR    = customer_Agent.AvailableTVR;
                topUpViewModel.AvailablePoint  = customer_Agent.AvailablePoint;
                topUpViewModel.NRIC            = customer_Agent.NRIC;
                topUpViewModel.CustomerName    = customer_Agent.CustomerName;


                return(View(topUpViewModel));
            }
        }
コード例 #15
0
        public JsonResult EditProductRedeem(AddProductRedeemViewModel model)
        {
            try
            {
                using (var db = new TourEntities())
                {
                    var formsAuthentication = HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName] != null
                  ? FormsAuthentication.Decrypt(
                        HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName].Value)
                  : null;

                    if (ModelState.IsValid)
                    {
                        var productRedeem = db.ProductRedeem.Find(model.ProductRedeemId);

                        if (model.ImagePath != null)
                        {
                            FileInfo path = new FileInfo(Server.MapPath("~/Image/Product/" + model.ImagePath));
                            path.Delete();

                            string imageName = System.IO.Path.GetFileName(model.ImagePath.FileName);
                            imageName = MetadataServices.GetDateTimeWithoutSlash() + "-" + imageName;
                            string physicalPath = Server.MapPath("~/Image/Product/" + imageName);
                            model.ImagePath.SaveAs(physicalPath);

                            productRedeem.ImagePath = imageName;
                        }

                        productRedeem.ProductRedeemName = model.ProductRedeemName;
                        productRedeem.Stock             = model.Stock;
                        productRedeem.RedeemPoint       = model.RedeemPoint;
                        productRedeem.UpdatedBy         = MetadataServices.GetCurrentUser().Username;
                        productRedeem.UpdatedAt         = MetadataServices.GetCurrentDate();

                        db.SaveChanges();
                    }
                    return(Json(new { }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #16
0
        public JsonResult EditGoodNews(AddGoodNewsViewModel model)
        {
            try
            {
                using (var db = new TourEntities())
                {
                    var formsAuthentication = HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName] != null
                  ? FormsAuthentication.Decrypt(
                        HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName].Value)
                  : null;

                    if (ModelState.IsValid)
                    {
                        var news = db.GoodNews.Find(model.GoodNewsId);

                        if (model.PhotoPath != null)
                        {
                            FileInfo path = new FileInfo(Server.MapPath("~/Image/GoodNews/" + news.PhotoPath));
                            path.Delete();

                            string imageName = System.IO.Path.GetFileName(model.PhotoPath.FileName);
                            imageName = MetadataServices.GetDateTimeWithoutSlash() + "-" + imageName;
                            string physicalPath = Server.MapPath("~/Image/GoodNews/" + imageName);
                            model.PhotoPath.SaveAs(physicalPath);

                            news.PhotoPath = imageName;
                        }

                        news.GoodNewsTitle = model.GoodNewsTitle;
                        news.Description   = model.Description;
                        news.UpdatedBy     = MetadataServices.GetCurrentUser().Username;
                        news.UpdatedAt     = MetadataServices.GetCurrentDate();

                        db.SaveChanges();
                    }
                    return(Json(new { }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #17
0
        public JsonResult AddPackage(AddPackageViewModel model)
        {
            using (var db = new TourEntities())
            {
                if (ModelState.IsValid)
                {
                    var formsAuthentication = HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName] != null
                    ? FormsAuthentication.Decrypt(
                        HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName].Value)
                    : null;

                    string imageName = System.IO.Path.GetFileName(model.PhotoPath.FileName);
                    imageName = MetadataServices.GetDateTimeWithoutSlash() + "-" + imageName;
                    string physicalPath = Server.MapPath("~/Image/Package/" + imageName);
                    model.PhotoPath.SaveAs(physicalPath);

                    string fileName = System.IO.Path.GetFileName(model.ItineraryFile.FileName);
                    fileName = MetadataServices.GetDateTimeWithoutSlash() + "-" + fileName;
                    string filePath = Server.MapPath("~/Files/" + fileName);
                    model.ItineraryFile.SaveAs(filePath);

                    var newPackage = new Package()
                    {
                        PackageName     = model.PackageName,
                        PhotoPath       = imageName,
                        FilePath        = fileName,
                        Description     = model.Description == null ? "" : model.Description,
                        IteneraryDetail = model.IteneraryDetail == null ? "" : model.IteneraryDetail,
                        TVR             = model.TVR,
                        Amount          = model.Amount,
                        CreatedBy       = MetadataServices.GetCurrentUser().Username,
                        CreatedAt       = MetadataServices.GetCurrentDate(),
                        UpdatedBy       = MetadataServices.GetCurrentUser().Username,
                        UpdatedAt       = MetadataServices.GetCurrentDate(),
                        IsDeleted       = false
                    };
                    db.Package.Add(newPackage);
                    db.SaveChanges();
                }
                return(Json(new { }, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #18
0
        public ActionResult UpdateAgentProfile(EditAgentProfileViewModel model)
        {
            using (var db = new TourEntities())
            {
                if (ModelState.IsValid)
                {
                    var agent = db.Agent.Find(model.AgentId);
                    var user  = db.User.Find(MetadataServices.GetCurrentUser().UserId);

                    if (agent == null || user == null)
                    {
                        return(new HttpNotFoundResult("Agent not found."));
                    }

                    bool chkIC = db.Agent.Where(x => x.NRIC == model.NRIC).Any();

                    if (!chkIC)
                    {
                        agent.AgentCode = Convert.ToInt32(model.NRIC.Substring(model.NRIC.Length - 6));
                    }

                    user.EmailAddress       = model.EmailAddress;
                    agent.AgentName         = model.AgentName;
                    agent.BankName          = model.BankName;
                    agent.BankAccountNumber = model.BankAccountNumber;
                    agent.Address           = model.Address;
                    agent.DOB         = model.DOB;
                    agent.NRIC        = model.NRIC;
                    agent.PhoneNumber = model.PhoneNumber;
                    agent.UserId      = user.UserId;
                    agent.UpdatedAt   = MetadataServices.GetCurrentDate();
                    agent.UpdatedBy   = MetadataServices.GetCurrentUser().Username;

                    db.SaveChanges();
                    return(RedirectToAction("UpdateAgentProfile", "Agent"));
                }
                return(View(model));
            }
        }
コード例 #19
0
 public ActionResult AgentTransaction()
 {
     using (var db = new TourEntities())
     {
         int userId = MetadataServices.GetCurrentUser().UserId;
         List <AgentTransactionViewModel> agentTransaction = (from data in db.AgentTransaction
                                                              where data.AgentTransactionId == userId
                                                              select new AgentTransactionViewModel()
         {
             AgentTransactionId = data.AgentTransactionId,
             AgentId = data.AgentId,
             CreditAmount = data.CreditAmount,
             FinalAmount = data.FinalAmount,
             CreditBonus = data.CreditBonus,
             FinalBonus = data.FinalBonus,
             DebitAmount = data.DebitAmount,
             DebitBonus = data.DebitBonus,
             CreatedAt = data.CreatedAt,
             CreatedBy = data.CreatedBy
         }).ToList();
         return(View(agentTransaction));
     }
 }
コード例 #20
0
        public JsonResult AddMerchant(AddMerchantViewModel model)
        {
            using (var db = new TourEntities())
            {
                if (ModelState.IsValid)
                {
                    var formsAuthentication = HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName] != null
                    ? FormsAuthentication.Decrypt(
                        HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName].Value)
                    : null;

                    string imageName = System.IO.Path.GetFileName(model.MerchantLogoPath.FileName);
                    imageName = MetadataServices.GetDateTimeWithoutSlash() + "-" + imageName;
                    string physicalPath = Server.MapPath("~/Image/Merchant/" + imageName);
                    model.MerchantLogoPath.SaveAs(physicalPath);

                    var newMerchant = new Merchant()
                    {
                        MerchantId           = model.MerchantId,
                        MerchantName         = model.MerchantName,
                        MerchantRegisterCode = model.MerchantRegisterCode,
                        MerchantPhoneNumber  = model.MerchantPhoneNumber,
                        MerchantAddress      = model.MerchantAddress,
                        MerchantCategoryId   = model.GetMerchantCategoryId,
                        MerchantJoinDate     = model.MerchantJoinDate,
                        MerchantLogoPath     = imageName,
                        CreatedBy            = MetadataServices.GetCurrentUser().Username,
                        CreatedAt            = MetadataServices.GetCurrentDate(),
                        UpdatedBy            = MetadataServices.GetCurrentUser().Username,
                        UpdatedAt            = MetadataServices.GetCurrentDate()
                    };
                    db.Merchant.Add(newMerchant);
                    db.SaveChanges();
                }
                return(Json(new { }, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #21
0
        public JsonResult AddTravelPromotion(TravelPromotionViewModel model)
        {
            using (var db = new TourEntities())
            {
                if (ModelState.IsValid)
                {
                    var formsAuthentication = HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName] != null
                    ? FormsAuthentication.Decrypt(
                        HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName].Value)
                    : null;

                    TravelPromotion travelPromotion = new TravelPromotion();
                    if (model.Description == null)
                    {
                        travelPromotion.Description = "";
                    }
                    else
                    {
                        travelPromotion.Description = model.Description;
                    }
                    string imageName = System.IO.Path.GetFileName(model.Image.FileName);
                    imageName = MetadataServices.GetDateTimeWithoutSlash() + "-" + imageName;
                    string physicalPath = Server.MapPath("~/Image/TravelPromotionImage/" + imageName);
                    model.Image.SaveAs(physicalPath);

                    travelPromotion.TravelPromotionTitle = model.TravelPromotionTitle;
                    travelPromotion.PhotoPath            = imageName;
                    travelPromotion.CreatedAt            = MetadataServices.GetCurrentDate();
                    travelPromotion.CreatedBy            = MetadataServices.GetCurrentUser().Username;
                    travelPromotion.UpdatedAt            = MetadataServices.GetCurrentDate();
                    travelPromotion.UpdatedBy            = MetadataServices.GetCurrentUser().Username;
                    db.TravelPromotion.Add(travelPromotion);
                    db.SaveChanges();
                }
                return(Json(new { }, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #22
0
        public JsonResult UpdatePassword(UserViewModel model)
        {
            string error = "";

            using (var db = new TourEntities())
            {
                var formsAuthentication = HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName] != null
              ? FormsAuthentication.Decrypt(
                    HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName].Value)
              : null;

                if (model.CurrentPassword != null && model.Password != null)
                {
                    var user = db.User.Find(MetadataServices.GetCurrentUser().UserId);

                    if (PasswordHash.ValidatePassword(model.CurrentPassword, user.Password))
                    {
                        user.Password  = PasswordHash.CreateHash(model.Password);
                        user.UpdatedAt = MetadataServices.GetCurrentDate();
                        user.UpdatedBy = MetadataServices.GetCurrentUser().Username;

                        db.SaveChanges();
                    }
                    else
                    {
                        error = "Invalid Current Password.";
                    }
                }
                else
                {
                    error = "Invalid Current Password.";
                }

                return(Json(new { error = error }, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #23
0
        public JsonResult SignUp(SignUpViewModel model)
        {
            int amount = 0;

            using (var db = new TourEntities())
            {
                var agent = db.Agent.FirstOrDefault(e => e.AgentCode == model.AgentCode);
                if (agent == null)
                {
                    ModelState.AddModelError("AgentCode", "Agent Code is not found.");
                }

                var introducer = new Customer();
                if (!string.IsNullOrEmpty(model.IntroducerCode))
                {
                    introducer = db.Customer.FirstOrDefault(e => e.CustomerCode == model.IntroducerCode);
                    if (introducer == null)
                    {
                        ModelState.AddModelError("IntroducerCode", "Introducer Code is not found.");
                    }
                }
                var systemSetting = db.SystemSetting.OrderByDescending(x => x.CreadtedDate).FirstOrDefault();

                if (model.TopUpAmountValue == "Other")
                {
                    if ((model.OtherAmount % systemSetting.MinAmount) != 0 || model.OtherAmount == 0)
                    {
                        ModelState.AddModelError("OtherAmount", "Other Amount not multiply of " + systemSetting.MinAmount);
                    }
                    else
                    {
                        amount = model.OtherAmount;
                    }
                }
                else
                {
                    amount = Convert.ToInt32(model.TopUpAmountValue);
                }

                var userWithNRIC = db.Customer.Where(x => x.NRIC == model.NRIC).FirstOrDefault();

                if (userWithNRIC != null)
                {
                    ModelState.AddModelError("NRIC", "NRIC Duplication");
                }

                var userWithUsername = db.User.Where(x => x.Username == model.Username).FirstOrDefault();

                if (userWithUsername != null)
                {
                    ModelState.AddModelError("Username", "Username Duplication");
                }

                if (ModelState.IsValid)
                {
                    var user = new User()
                    {
                        Username     = model.Username,
                        EmailAddress = model.EmailAddress,
                        Password     = PasswordHash.CreateHash(model.Password),
                        RoleId       = TourRoleId.Customer,
                        CreatedAt    = MetadataServices.GetCurrentDate(),
                        CreatedBy    = model.Username,
                        UpdatedAt    = MetadataServices.GetCurrentDate(),
                        UpdatedBy    = model.Username,
                        IsActive     = false,
                        IsDeleted    = false,
                    };
                    db.User.Add(user);
                    db.SaveChanges();

                    string customerCode = model.NRIC.GetLast(6);
                    var    customer     = new Customer()
                    {
                        CustomerName      = model.CustomerName,
                        NRIC              = model.NRIC,
                        CustomerCode      = customerCode,
                        BankAccountNumber = model.BankAccountNumber,
                        PhoneNumber       = model.PhoneNumber,
                        Address           = model.Address,
                        AvailableTVR      = 0,
                        AvailableAmount   = 0,
                        AvailablePoint    = 0,
                        AgentId           = agent.AgentId,
                        IntroducerId      = introducer.CustomerId,
                        JoinDate          = MetadataServices.GetCurrentDate(),
                        UserId            = user.UserId,
                        CreatedAt         = MetadataServices.GetCurrentDate(),
                        CreatedBy         = model.Username,
                        UpdatedAt         = MetadataServices.GetCurrentDate(),
                        UpdatedBy         = model.Username,
                        DateOfBirth       = model.DateOfBirth,
                        RenewDate         = MetadataServices.GetCurrentDate(),
                        ExpiredDate       = MetadataServices.GetCurrentDate(),
                        BankName          = model.BankName,
                        IsDeleted         = false
                    };
                    db.Customer.Add(customer);
                    db.SaveChanges();

                    var customerNew = db.Customer.FirstOrDefault(e => e.CustomerCode == customerCode);


                    string imageName = "";

                    if (model.Image != null)
                    {
                        imageName = System.IO.Path.GetFileName(model.Image.FileName);
                        imageName = MetadataServices.GetDateTimeWithoutSlash() + "-" + imageName;
                        string physicalPath = Server.MapPath("~/Image/TransactionImage/" + imageName);
                        model.Image.SaveAs(physicalPath);
                    }

                    var userTransaction = new UserTransaction()
                    {
                        AgentId           = agent.AgentId,
                        CustomerId        = customerNew.CustomerId,
                        IntroducerId      = customerNew.IntroducerId,
                        ReferenceNo       = MetadataServices.GenerateCode(6),
                        ActivityId        = (int)Helpers.TransactionActivity.SignUp,
                        PathForProof      = imageName,
                        Amount            = 0,
                        CurrentTVR        = 0,
                        TopUpTVR          = systemSetting.TVRMutiply * amount,
                        RedeemTVR         = 0,
                        BalanceTVR        = 0,
                        CurrentPoint      = 0,
                        PointAdd          = ((amount / systemSetting.MinAmount) * systemSetting.PointCalculation),
                        PointRedeem       = 0,
                        PointBalance      = 0,
                        ActionDate        = null,
                        Remarks           = "",
                        CreatedAt         = MetadataServices.GetCurrentDate(),
                        CreatedBy         = model.Username,
                        UpdatedAt         = MetadataServices.GetCurrentDate(),
                        UpdatedBy         = model.Username,
                        IsDeleted         = false,
                        TransactionStatus = (int)TransactionStatus.Pending
                    };
                    db.UserTransaction.Add(userTransaction);
                    db.SaveChanges();

                    return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    List <string> errors = new List <string>();

                    foreach (ModelState modelState in ViewData.ModelState.Values)
                    {
                        foreach (ModelError error in modelState.Errors)
                        {
                            errors.Add(string.IsNullOrEmpty(error.ErrorMessage) ? error.Exception.ToString() : error.ErrorMessage);
                        }
                    }
                    return(Json(new { success = false, errors = errors }, JsonRequestBehavior.AllowGet));
                }
            }
        }
コード例 #24
0
        protected virtual void WritePropertyValue([NotNull] IPropertyBase propertyBase, [CanBeNull] object value)
        {
            Debug.Assert(!(propertyBase is IProperty) || !((IProperty)propertyBase).IsShadowProperty);

            MetadataServices.WriteValue(Entity, propertyBase, value);
        }
コード例 #25
0
 private static IEnumerable <MethodInfo> GetVisibleExtensionMethodsFast(Assembly assembly)
 {
     // Security: link demand
     return(MetadataServices.GetVisibleExtensionMethodInfos(assembly));
 }
コード例 #26
0
 public virtual EntityKey CreateKey(
     [NotNull] IKey key,
     [NotNull] IReadOnlyList <IProperty> properties,
     [NotNull] IPropertyAccessor propertyAccessor) => MetadataServices.CreateKey(key, properties, propertyAccessor);
コード例 #27
0
        public JsonResult RedeemPackage(ViewPackageViewModel model)
        {
            try
            {
                using (var db = new TourEntities())
                {
                    int amountHeadCount = 0;

                    if (model.PersonAmountValue == "Other")
                    {
                        if (Convert.ToInt32(model.OtherPersonAmountValue) == 0 || model.OtherPersonAmountValue == null)
                        {
                            ModelState.AddModelError("OtherPersonAmountValue", "Other Headcount amount cannot be 0 or empty");
                        }
                        else
                        {
                            amountHeadCount = Convert.ToInt32(model.OtherPersonAmountValue);
                        }
                    }
                    else
                    {
                        amountHeadCount = Convert.ToInt32(model.PersonAmountValue);
                    }

                    var package = db.Package.FirstOrDefault(e => e.PackageId == model.PackageId);
                    if (package == null)
                    {
                        ModelState.AddModelError("PackageId", "Package is not found.");
                    }

                    var user     = MetadataServices.GetCurrentUser();
                    var customer = db.Customer.Where(x => x.UserId == user.UserId).FirstOrDefault();

                    decimal totalAmount = amountHeadCount * package.Amount;
                    int     totalTVR    = amountHeadCount * package.TVR;

                    if (customer.AvailableTVR < totalTVR)
                    {
                        ModelState.AddModelError("TVR", "Your current available is not enough. Please proceed to top up.");
                    }

                    if (ModelState.IsValid)
                    {
                        string imageName = "";

                        if (model.Image != null)
                        {
                            imageName = System.IO.Path.GetFileName(model.Image.FileName);
                            imageName = MetadataServices.GetDateTimeWithoutSlash() + "-" + imageName;
                            string physicalPath = Server.MapPath("~/Image/TransactionImage/" + imageName);
                            model.Image.SaveAs(physicalPath);
                        }

                        int balanceTVR      = (customer.AvailableTVR - totalTVR);
                        var userTransaction = new UserTransaction()
                        {
                            AgentId           = customer.AgentId,
                            CustomerId        = customer.CustomerId,
                            IntroducerId      = customer.IntroducerId,
                            ReferenceNo       = MetadataServices.GenerateCode(6),
                            ActivityId        = (int)Helpers.TransactionActivity.RedeemPackage,
                            PathForProof      = imageName,
                            Amount            = customer.AvailableAmount,
                            CurrentTVR        = customer.AvailableTVR,
                            TopUpTVR          = 0,
                            RedeemTVR         = totalTVR,
                            BalanceTVR        = balanceTVR,
                            CurrentPoint      = customer.AvailablePoint,
                            PointAdd          = 0,
                            PointRedeem       = 0,
                            PointBalance      = 0,
                            ActionDate        = null,
                            Remarks           = "",
                            PackageId         = model.PackageId,
                            TravelHeadCount   = amountHeadCount,
                            CreatedAt         = MetadataServices.GetCurrentDate(),
                            CreatedBy         = user.Username,
                            UpdatedAt         = MetadataServices.GetCurrentDate(),
                            UpdatedBy         = user.Username,
                            IsDeleted         = false,
                            TransactionStatus = (int)TransactionStatus.Pending
                        };

                        db.UserTransaction.Add(userTransaction);

                        var customerTransaction = new IntroducerTransaction()
                        {
                            IntroducerId = customer.CustomerId,
                            CreditTVR    = 0,
                            FinalTVR     = balanceTVR,
                            DebitTVR     = totalTVR,
                            CreditAmount = 0,
                            FinalAmount  = customer.AvailableAmount,
                            DebitAmount  = 0,
                            CreditPoint  = 0,
                            FinalPoint   = customer.AvailablePoint,
                            DebitPoint   = 0,
                            CreatedBy    = user.Username,
                            CreatedAt    = DateTime.Now
                        };

                        db.IntroducerTransaction.Add(customerTransaction);

                        customer.AvailableTVR = customer.AvailableTVR - totalTVR;

                        db.SaveChanges();

                        return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        List <string> errors = new List <string>();

                        foreach (ModelState modelState in ViewData.ModelState.Values)
                        {
                            foreach (ModelError error in modelState.Errors)
                            {
                                errors.Add(string.IsNullOrEmpty(error.ErrorMessage) ? error.Exception.ToString() : error.ErrorMessage);
                            }
                        }
                        return(Json(new { success = false, errors = errors }, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
        }
コード例 #28
0
        public JsonResult EditPackage(AddPackageViewModel model)
        {
            try
            {
                using (var db = new TourEntities())
                {
                    var formsAuthentication = HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName] != null
                  ? FormsAuthentication.Decrypt(
                        HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName].Value)
                  : null;

                    if (ModelState.IsValid)
                    {
                        var package = db.Package.Find(model.PackageId);

                        if (model.PhotoPath != null)
                        {
                            FileInfo path = new FileInfo(Server.MapPath("~/Image/Package/" + package.PhotoPath));
                            path.Delete();

                            string imageName = System.IO.Path.GetFileName(model.PhotoPath.FileName);
                            imageName = MetadataServices.GetDateTimeWithoutSlash() + "-" + imageName;
                            string physicalPath = Server.MapPath("~/Image/Package/" + imageName);
                            model.PhotoPath.SaveAs(physicalPath);

                            package.PhotoPath = imageName;
                        }

                        if (model.ItineraryFile != null)
                        {
                            if (!string.IsNullOrEmpty(package.FilePath))
                            {
                                FileInfo path = new FileInfo(Server.MapPath("~/Files/" + package.FilePath));
                                path.Delete();
                            }

                            string fileName = System.IO.Path.GetFileName(model.ItineraryFile.FileName);
                            fileName = MetadataServices.GetDateTimeWithoutSlash() + "-" + fileName;
                            string filePath = Server.MapPath("~/Files/" + fileName);
                            model.ItineraryFile.SaveAs(filePath);

                            package.FilePath = fileName;
                        }

                        package.PackageName     = model.PackageName;
                        package.Description     = model.Description;
                        package.IteneraryDetail = (string.IsNullOrEmpty(model.IteneraryDetail)? "" : model.IteneraryDetail);
                        package.TVR             = model.TVR;
                        package.Amount          = model.Amount;
                        package.UpdatedBy       = MetadataServices.GetCurrentUser().Username;
                        package.UpdatedAt       = MetadataServices.GetCurrentDate();

                        db.SaveChanges();
                    }
                    return(Json(new { }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #29
0
        public JsonResult TopUpCustomer(TopUpViewModel topUpVieModel)
        {
            using (var db = new TourEntities())
            {
                int amount = 0;

                var systemSetting = db.SystemSetting.OrderByDescending(x => x.CreadtedDate).FirstOrDefault();

                if (topUpVieModel.TopUpAmountValue == "Other")
                {
                    if ((topUpVieModel.OtherAmount % systemSetting.MinAmount) != 0 || topUpVieModel.OtherAmount == 0)
                    {
                        ModelState.AddModelError("OtherAmount", "Other Amount not multiply of " + systemSetting.MinAmount);
                    }
                    else
                    {
                        amount = topUpVieModel.OtherAmount;
                    }
                }
                else
                {
                    amount = Convert.ToInt32(topUpVieModel.TopUpAmountValue);
                }

                if (ModelState.IsValid)
                {
                    var user     = MetadataServices.GetCurrentUser();
                    var customer = db.Customer.Where(x => x.UserId == user.UserId).FirstOrDefault();

                    string imageName = "";

                    if (topUpVieModel.Image != null)
                    {
                        imageName = System.IO.Path.GetFileName(topUpVieModel.Image.FileName);
                        imageName = MetadataServices.GetDateTimeWithoutSlash() + "-" + imageName;
                        string physicalPath = Server.MapPath("~/Image/TransactionImage/" + imageName);
                        topUpVieModel.Image.SaveAs(physicalPath);
                    }

                    var userTransaction = new UserTransaction()
                    {
                        AgentId           = customer.AgentId,
                        CustomerId        = customer.CustomerId,
                        IntroducerId      = customer.IntroducerId,
                        ReferenceNo       = MetadataServices.GenerateCode(6),
                        ActivityId        = (int)Helpers.TransactionActivity.TopUp,
                        PathForProof      = imageName,
                        Amount            = amount,
                        CurrentTVR        = customer.AvailableTVR,
                        TopUpTVR          = systemSetting.TVRMutiply * amount,
                        RedeemTVR         = 0,
                        BalanceTVR        = 0,
                        CurrentPoint      = customer.AvailablePoint,
                        PointAdd          = ((amount / systemSetting.MinAmount) * systemSetting.PointCalculation),
                        PointRedeem       = 0,
                        PointBalance      = 0,
                        ActionDate        = null,
                        Remarks           = "",
                        CreatedAt         = MetadataServices.GetCurrentDate(),
                        CreatedBy         = MetadataServices.GetCurrentUser().Username,
                        UpdatedAt         = MetadataServices.GetCurrentDate(),
                        UpdatedBy         = MetadataServices.GetCurrentUser().Username,
                        IsDeleted         = false,
                        TransactionStatus = (int)TransactionStatus.Pending
                    };


                    db.UserTransaction.Add(userTransaction);
                    db.SaveChanges();
                    return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    List <string> errors = new List <string>();

                    foreach (ModelState modelState in ViewData.ModelState.Values)
                    {
                        foreach (ModelError error in modelState.Errors)
                        {
                            errors.Add(string.IsNullOrEmpty(error.ErrorMessage) ? error.Exception.ToString() : error.ErrorMessage);
                        }
                    }
                    return(Json(new { success = false, errors = errors }, JsonRequestBehavior.AllowGet));
                }
            }
        }
コード例 #30
0
        public JsonResult RedeemPoint(ViewPointRedemption model)
        {
            try
            {
                using (var db = new TourEntities())
                {
                    var product = db.ProductRedeem.Where(x => x.ProductRedeemId == model.ProductRedeemId).FirstOrDefault();
                    if (product == null)
                    {
                        ModelState.AddModelError("ProductRedeemId", "Product Redeem is not found.");
                    }

                    var user     = MetadataServices.GetCurrentUser();
                    var customer = db.Customer.Where(x => x.UserId == user.UserId).FirstOrDefault();

                    if (customer.AvailablePoint < model.RedeemPoint)
                    {
                        ModelState.AddModelError("RedeemPoint", "Not Enough Redeem Point.");
                    }


                    if (ModelState.IsValid)
                    {
                        int balancePoint = (customer.AvailablePoint - product.RedeemPoint);

                        var userTransaction = new UserTransaction()
                        {
                            AgentId           = customer.AgentId,
                            CustomerId        = customer.CustomerId,
                            IntroducerId      = customer.IntroducerId,
                            ReferenceNo       = MetadataServices.GenerateCode(6),
                            ActivityId        = (int)Helpers.TransactionActivity.RedeemPoint,
                            Amount            = customer.AvailableAmount,
                            PathForProof      = string.Empty,
                            CurrentTVR        = customer.AvailableTVR,
                            TopUpTVR          = 0,
                            RedeemTVR         = 0,
                            BalanceTVR        = 0,
                            CurrentPoint      = customer.AvailablePoint,
                            PointAdd          = 0,
                            PointRedeem       = product.RedeemPoint,
                            PointBalance      = balancePoint,
                            ActionDate        = null,
                            Remarks           = "",
                            ProductId         = model.ProductRedeemId,
                            CreatedAt         = MetadataServices.GetCurrentDate(),
                            CreatedBy         = user.Username,
                            UpdatedAt         = MetadataServices.GetCurrentDate(),
                            UpdatedBy         = user.Username,
                            IsDeleted         = false,
                            TransactionStatus = (int)TransactionStatus.Pending
                        };

                        db.UserTransaction.Add(userTransaction);

                        var customerTransaction = new IntroducerTransaction()
                        {
                            IntroducerId = customer.CustomerId,
                            CreditTVR    = 0,
                            FinalTVR     = customer.AvailableTVR,
                            DebitTVR     = 0,
                            CreditAmount = 0,
                            FinalAmount  = customer.AvailableAmount,
                            DebitAmount  = 0,
                            CreditPoint  = 0,
                            FinalPoint   = balancePoint,
                            DebitPoint   = product.RedeemPoint,
                            CreatedBy    = user.Username,
                            CreatedAt    = DateTime.Now
                        };

                        db.IntroducerTransaction.Add(customerTransaction);

                        customer.AvailablePoint = balancePoint;

                        db.SaveChanges();
                        return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        List <string> errors = new List <string>();

                        foreach (ModelState modelState in ViewData.ModelState.Values)
                        {
                            foreach (ModelError error in modelState.Errors)
                            {
                                errors.Add(string.IsNullOrEmpty(error.ErrorMessage) ? error.Exception.ToString() : error.ErrorMessage);
                            }
                        }
                        return(Json(new { success = false, errors = errors }, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
        }