public ActionResult ConfirmAccount() { ViewBag.message = @"<script type='text/javascript' language='javascript'>alert(""Invalid activation code"")</script>"; if (RouteData.Values["RoleID"] != null) { Guid activationCode = new Guid(RouteData.Values["RoleID"].ToString()); //LaxNarroEntities usersEntities = new LaxNarroEntities(); User_Profile userActivation = db.User_Profile.Where(p => p.ActivationCode == activationCode).FirstOrDefault(); if (userActivation != null) { //usersEntities.User_Profile.Remove(userActivation); if (userActivation.AccountConfirmed == "Yes") { ViewBag.Status = "This account has already been activated. If you have forgotton your " + "password click on forget password on login page."; } else { userActivation.AccountConfirmed = "Yes"; db.Entry(userActivation).State = EntityState.Modified; db.SaveChanges(); SendMail(userActivation.FirstName, userActivation.LastName, userActivation.EmailAddress, "", "~/EmailTemplate/AccountValidated.html"); ViewBag.Status = "Thank you for confirming your account. Now you can Login and start using our services."; } } } return(View()); }
public ActionResult Edit([Bind(Include = "Id,StateID,ActivityID,Rule2_ID,StartDate,EndDate,Status")] StateActivity__with_Rule2 stateActivity__with_Rule2) { try { ViewBag.ActivityID = new SelectList(db.Activity_Master.OrderBy(m => m.Name), "ID", "Name", stateActivity__with_Rule2.ActivityID); ViewBag.Rule2_ID = new SelectList(db.Rule2_Master.OrderBy(m => m.Name), "Id", "Name", stateActivity__with_Rule2.Rule2_ID); ViewBag.StateID = new SelectList(db.State_Master.OrderBy(m => m.Name), "ID", "Name", stateActivity__with_Rule2.StateID); if (stateActivity__with_Rule2.StartDate > stateActivity__with_Rule2.EndDate) { ViewBag.message = ToasterMessage.Message(ToastType.info, "End date should be greater then start date"); return(View()); } else { List <StateActivity__with_Rule2> getName = db.StateActivity__with_Rule2.Where(u => u.StateID == stateActivity__with_Rule2.StateID && u.Rule2_ID == stateActivity__with_Rule2.Rule2_ID && u.StartDate == stateActivity__with_Rule2.StartDate && u.EndDate == stateActivity__with_Rule2.EndDate && u.Status == stateActivity__with_Rule2.Status && u.ActivityID == stateActivity__with_Rule2.ActivityID && u.Id != stateActivity__with_Rule2.Id).ToList(); if (getName.Count > 0) { ViewBag.message = ToasterMessage.Message(ToastType.info, "Record already exist"); return(View()); } else { db.Entry(stateActivity__with_Rule2).State = EntityState.Modified; db.SaveChanges(); TempData["message"] = ToasterMessage.Message(ToastType.success, "Updated Successfully"); return(RedirectToAction("Index")); } } } catch (DbEntityValidationException e) { string errorMessage = string.Empty; foreach (DbEntityValidationResult eve in e.EntityValidationErrors) { System.Diagnostics.Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (DbValidationError ve in eve.ValidationErrors) { System.Diagnostics.Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); errorMessage = ve.ErrorMessage; ViewBag.message = ViewBag.message + ToasterMessage.Message(ToastType.error, errorMessage); } } return(View()); } catch (Exception) { ViewBag.message = ToasterMessage.Message(ToastType.error, "Something went wrong"); } return(View()); }
public ActionResult Edit([Bind(Include = "Rate_Id,Plan_Id,StartDate,EndDate,Amount,Status")] Rate_Card rate_Card) { ViewBag.Plan_Id = new SelectList(db.Plan_Master.OrderBy(m => m.Plan), "Plan_ID", "Plan"); try { //if (ModelState.IsValid) //{ if (rate_Card.StartDate > rate_Card.EndDate) { ViewBag.message = ToasterMessage.Message(ToastType.info, "End date should be greater then start date"); return(View()); } else { var getName = db.Rate_Card.Where(u => u.Plan_Id == rate_Card.Plan_Id && u.StartDate == rate_Card.StartDate && u.EndDate == rate_Card.EndDate && u.Status == rate_Card.Status && u.Plan_Id != rate_Card.Plan_Id).ToList(); if (getName.Count > 0) { ViewBag.message = ToasterMessage.Message(ToastType.info, "Record already exist"); return(View()); } else { db.Entry(rate_Card).State = EntityState.Modified; db.SaveChanges(); TempData["message"] = ToasterMessage.Message(ToastType.success, "Updated Successfully"); return(RedirectToAction("Index")); } } //} } catch (DbEntityValidationException e) { string errorMessage = string.Empty; foreach (DbEntityValidationResult 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 (DbValidationError ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); errorMessage = ve.ErrorMessage; ViewBag.message = ViewBag.message + ToasterMessage.Message(ToastType.error, errorMessage); } } return(View()); } catch (Exception) { ViewBag.message = ToasterMessage.Message(ToastType.error, "Something went wrong"); } return(View()); }
public ActionResult Edit([Bind(Include = "ID,Name,ShortName,Country_ID")] State_Master state_Master) { try { ViewBag.Country_ID = new SelectList(db.Country_Master.OrderBy(m => m.Name), "ID", "Name", state_Master.Country_ID); //if (ModelState.IsValid) //{ var getName = db.State_Master.Where(u => u.Name == state_Master.Name && u.Country_ID == state_Master.Country_ID && u.ID != state_Master.ID).ToList(); if (getName.Count > 0) { ViewBag.message = ToasterMessage.Message(ToastType.info, "Record already exists."); return(View()); } else { db.Entry(state_Master).State = EntityState.Modified; db.SaveChanges(); TempData["message"] = ToasterMessage.Message(ToastType.success, "Updated successfully."); return(RedirectToAction("Index")); } //} } catch (DbEntityValidationException e) { string errorMessage = string.Empty; foreach (DbEntityValidationResult 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 (DbValidationError ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); errorMessage = ve.ErrorMessage; ViewBag.message = ViewBag.message + ToasterMessage.Message(ToastType.error, errorMessage); } } return(View()); } catch (Exception) { ViewBag.message = ToasterMessage.Message(ToastType.error, "Something went wrong."); } return(View()); }
public ActionResult Edit([Bind(Include = "Plan_ID,Plan")] Plan_Master plan_Master) { try { //if (ModelState.IsValid) //{ var getName = db.Plan_Master.Where(u => u.Plan == plan_Master.Plan && u.Plan_ID != plan_Master.Plan_ID).ToList(); if (getName.Count > 0) { ViewBag.message = ToasterMessage.Message(ToastType.info, "Record already exist"); return(View()); } else { db.Entry(plan_Master).State = EntityState.Modified; db.SaveChanges(); TempData["message"] = ToasterMessage.Message(ToastType.success, "Updated Successfully"); return(RedirectToAction("Index")); } //} } catch (DbEntityValidationException e) { string errorMessage = string.Empty; foreach (DbEntityValidationResult 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 (DbValidationError ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); errorMessage = ve.ErrorMessage; ViewBag.message = ViewBag.message + ToasterMessage.Message(ToastType.error, errorMessage); } } return(View()); } catch (Exception) { ViewBag.message = ToasterMessage.Message(ToastType.error, "Something went wrong"); } return(View()); }
public ActionResult Edit(UserProfileEditViewModel userProfileEdit) { if (userProfileEdit.ID != Convert.ToDecimal(UserHelper.GetUserId())) { TempData["message"] = ToasterMessage.Message(ToastType.warning, "Unauthorized Access"); return(RedirectToAction("Index")); } User_Profile user_Profile = db.User_Profile.Find(userProfileEdit.ID); try { ViewBag.CountryID = new SelectList(db.Country_Master.OrderBy(m => m.Name), "ID", "Name", user_Profile.CountryID); ViewBag.Role_id = new SelectList(db.Role_Master, "Id", "Name", user_Profile.Role_id); ViewBag.StateID = new SelectList(db.State_Master.OrderBy(m => m.Name), "ID", "Name", user_Profile.StateID); ViewBag.StateEnrolled = new SelectList(db.State_Master.OrderBy(m => m.Name), "ID", "Name", user_Profile.StateEnrolled); user_Profile.UserName = userProfileEdit.EmailAddress; user_Profile.FirstName = userProfileEdit.FirstName; user_Profile.LastName = userProfileEdit.LastName; user_Profile.OtherName = userProfileEdit.OtherName; user_Profile.StateID = userProfileEdit.StateID; user_Profile.StreetName = userProfileEdit.StreetName; user_Profile.StreetNumber = userProfileEdit.StreetNumber; user_Profile.PostCode = userProfileEdit.PostCode; user_Profile.Suburb = userProfileEdit.Suburb; user_Profile.LawSocietyNumber = userProfileEdit.LawSocietyNumber; user_Profile.PhoneNumber = userProfileEdit.PhoneNumber; user_Profile.Date = userProfileEdit.Date; user_Profile.Address = userProfileEdit.Address; db.Entry(user_Profile).State = EntityState.Modified; db.SaveChanges(); TempData["message"] = ToasterMessage.Message(ToastType.success, "Updated Successfully"); } catch (DbEntityValidationException e) { string errorMessage = string.Empty; foreach (DbEntityValidationResult 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 (DbValidationError ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); errorMessage = ve.ErrorMessage; ViewBag.message = ViewBag.message + ToasterMessage.Message(ToastType.error, errorMessage); } } return(View()); } return(RedirectToAction("Index")); }
public ActionResult Success(decimal planId, string payerId, string paymentId) { try { decimal userId = Convert.ToDecimal(UserHelper.GetUserId()); //-----For sending Invoice mail------ decimal recordId = 0; using (LaxNarroEntities ctx = new LaxNarroEntities()) { using (var transaction = ctx.Database.BeginTransaction()) { int?maxInvoice = ctx.User_Transaction_Master.Max(u => u.Invoice_No); Rate_Card rate_card = ctx.Rate_Card.Include(x => x.Plan_Master) .Where(m => m.Plan_Id == planId && m.Status == "Active").FirstOrDefault(); User_Transaction_Master userTransaction = new User_Transaction_Master(); IEnumerable <User_Transaction_Master> userAllTransaction = ctx.User_Transaction_Master .Where(x => x.User_ID == userId); // Set the payer for the payment var paymentExecution = new PaymentExecution() { payer_id = payerId }; // Identify the payment to execute var payment = new Payment() { id = paymentId }; var apiContext = GetAPIContext(); // Execute the Payment var executedPayment = payment.Execute(apiContext, paymentExecution); int?max = userAllTransaction.Max(u => (int?)u.Invoice_No); User_Transaction_Master maxedInvoicedTransaction = userAllTransaction .FirstOrDefault(x => x.User_ID == userId && x.Invoice_No == max); int?maxedInvoiceNo = ctx.User_Transaction_Master.Max(u => (int?)u.Invoice_No); if (executedPayment.state == "approved") { //---------For new payment record (second time payment and so on)------- if (maxedInvoicedTransaction.Payment_Status != "N/A") { userTransaction.Amount = Convert.ToDecimal(rate_card.Amount); DateTime?endDate = maxedInvoicedTransaction.End_Date; string strEndDate = string.Empty; if (endDate != null) { strEndDate = endDate.ToString(); } userTransaction.Start_Date = Convert.ToDateTime(strEndDate); if (rate_card.Plan_Master.Plan == "Yearly") { userTransaction.End_Date = userTransaction.Start_Date.AddYears(1); } else { userTransaction.End_Date = userTransaction.Start_Date.AddYears(2); } if (maxInvoice == null) { userTransaction.Invoice_No = 1; } else { userTransaction.Invoice_No = maxInvoice + 1; } userTransaction.Payment_Date = DateTime.Today; userTransaction.Payment_Method = "Online"; userTransaction.Payment_Status = "Paid"; userTransaction.Paypal_PayerId = payerId; userTransaction.PlanID = rate_card.Plan_Id; userTransaction.Rate_ID = rate_card.Rate_Id; userTransaction.Status = "Active"; userTransaction.Transaction_Status = executedPayment.state; userTransaction.Transection_ID = executedPayment.id; userTransaction.User_ID = userId; ctx.User_Transaction_Master.Add(userTransaction); ctx.SaveChanges(); recordId = userTransaction.Id; } //---------For updating the demo record (First time payment)------- else { maxedInvoicedTransaction.Amount = Convert.ToDecimal(rate_card.Amount); if (rate_card.Plan_Master.Plan == "Yearly") { maxedInvoicedTransaction.End_Date = DateTime.Today.AddYears(1); } else { maxedInvoicedTransaction.End_Date = DateTime.Today.AddYears(2); } if (maxInvoice == null) { maxedInvoicedTransaction.Invoice_No = 1; } else { maxedInvoicedTransaction.Invoice_No = maxInvoice + 1; } maxedInvoicedTransaction.Payment_Date = DateTime.Today; maxedInvoicedTransaction.Payment_Method = "Online"; maxedInvoicedTransaction.Payment_Status = "Paid"; maxedInvoicedTransaction.Paypal_PayerId = payerId; maxedInvoicedTransaction.PlanID = rate_card.Plan_Id; maxedInvoicedTransaction.Rate_ID = rate_card.Rate_Id; //DateTime? endDate = maxedInvoicedTransaction.End_Date; //string strEndDate = string.Empty; //if (endDate != null) // strEndDate = endDate.ToString(); maxedInvoicedTransaction.Start_Date = DateTime.Today; maxedInvoicedTransaction.Status = "Active"; maxedInvoicedTransaction.Transaction_Status = executedPayment.state; maxedInvoicedTransaction.Transection_ID = executedPayment.id; maxedInvoicedTransaction.User_ID = userId; ctx.Entry(maxedInvoicedTransaction).State = EntityState.Modified; ctx.SaveChanges(); recordId = maxedInvoicedTransaction.Id; } PaypalResponse paypalResponse = new PaypalResponse { user_id = userId, Paypal_ReferenceId = executedPayment.id, intent = executedPayment.intent, payer = Convert.ToString(executedPayment.payer), payee = Convert.ToString(executedPayment.payee), note_to_payer = executedPayment.note_to_payer, update_time = executedPayment.update_time, create_time = executedPayment.create_time, response_state = executedPayment.state, failure_reason = executedPayment.failure_reason }; ctx.PaypalResponses.Add(paypalResponse); ctx.SaveChanges(); transaction.Commit(); MailLog user = ctx.MailLogs.FirstOrDefault(x => x.UserID == userId); user.LastReminderStatus = "Deactive"; ctx.SaveChanges(); } Thread thread = new Thread(() => SendInvoice(recordId)); thread.Start(); User_Profile userMail = ctx.User_Profile.Where(p => p.ID == userId).FirstOrDefault(); Thread thread2 = new Thread(() => SendMail(userMail.FirstName, userMail.LastName, userMail.EmailAddress, "", "Lexnarro - Subscription Successful", "~/EmailTemplate/SubscriptionMail.html")); thread2.Start(); //SendMail(userMail.FirstName, userMail.LastName, userMail.EmailAddress, "", // "Lexnarro - Subscription Successful", "~/EmailTemplate/SubscriptionMail.html"); TempData["message"] = ToasterMessage.Message(ToastType.success, "Subscription successful. Thank you."); } } } catch (DbEntityValidationException e) { string errorMessage = string.Empty; foreach (DbEntityValidationResult 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 (DbValidationError ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); errorMessage = ve.ErrorMessage; TempData["message"] = ViewBag.message + ToasterMessage.Message(ToastType.error, errorMessage); } } } catch (Exception r) { TempData["message"] = ToasterMessage.Message(ToastType.error, "Something went wrong"); } return(RedirectToAction("Index")); }
public ReturnData DoCarryOver(string financialYear, string ids, string units, string userId, string stateId) { decimal unts = 0; string result = string.Empty; decimal user_Id = Convert.ToDecimal(userId); decimal enrolledStateId = Convert.ToDecimal(stateId); decimal?hoursRemoved = 0; decimal?unitsRemoved = 0; ReturnData rd = new ReturnData(); try { string nextFinancialYear = GetNewFinancialYear(financialYear); ids = ids.Trim('\\', '"', '[', ']'); string resultIds = ids.RemoverStrs(new[] { "\\", "\"", "[", "]" }); string resultUnits = units.RemoverStrs(new[] { "\\", "\"", "[", "]" }); string[] carryOverIds = resultIds.Split(','); string[] carryOverUnitsList = resultUnits.Split(','); using (LaxNarroEntities ctx = new LaxNarroEntities()) { using (DbContextTransaction transaction = ctx.Database.BeginTransaction()) { decimal?carryOverUnits = ctx.State_Rule3_Marriage.Include(x => x.Rule3_ID) .Where(x => x.StateID == enrolledStateId).Select(x => x.Rule3_Master.CarryOverUnits).First(); foreach (string item in carryOverUnitsList) { if (Convert.ToDecimal(item) <= 0) { //result = "Error - Please select units more then 0 (zero)"; transaction.Dispose(); rd.Status = "Error"; rd.Message = "Please select units more then 0 (Zero)"; rd.Requestkey = "DoCarryOver"; return(rd); } unts = unts + Convert.ToDecimal(item); } if (unts > carryOverUnits) { transaction.Dispose(); rd.Status = "Error"; rd.Message = "Selected units are more then the allowed units for carry over"; rd.Requestkey = "DoCarryOver"; return(rd); } //if (unts > carryOverUnits) //{ // transaction.Dispose(); // rd.Status = "Error"; // rd.Message = "Selected units are greater then allowed no. of units"; // rd.Requestkey = "DoCarryOver"; // return rd; //} for (int j = 0; j < carryOverIds.Length; j++) { decimal id = Convert.ToDecimal(carryOverIds[j]); User_Training_Transaction trainingToCreate = new User_Training_Transaction(); User_Training_Status trainingStatusToCreate = new User_Training_Status(); //Getting old records to update after carry over and creating new carried over records with same values as before //User_Training_Transaction utt = ctx.User_Training_Transaction.Find(id); //User_Training_Status uts = ctx.User_Training_Status.Where(x=>x.Training_Transaction_ID == id).First(); List <CarryOverTraining> userTraining = ctx.User_Training_Status.Include(x => x.User_Profile).Include(x => x.Category_Master) .Include(x => x.Activity_Master).Include(x => x.Sub_Activity_Master).Include(x => x.User_Training_Transaction) .Where(x => x.User_Training_Transaction.Id == id && x.Financial_Year == financialYear).Select(a => new CarryOverTraining() { TrainingStatusId = a.Id, TrainingTransactionId = a.User_Training_Transaction.Id, User_Id = a.User_Id, Date = a.User_Training_Transaction.Date, State_Id = a.User_Training_Transaction.State_Id, Category_Id = a.Category_Id, Activity_Id = a.Activity_Id, SubActivity_Id = a.SubActivity_Id, Hours = a.User_Training_Transaction.Hours, Provider = a.User_Training_Transaction.Provider, Financial_Year = a.Financial_Year, Your_Role = a.User_Training_Transaction.Your_Role, Forwardable = a.User_Training_Transaction.Forwardable, Has_been_Forwarded = a.User_Training_Transaction.Has_been_Forwarded, Descrption = a.User_Training_Transaction.Descrption, UploadedFile = a.User_Training_Transaction.UploadedFile, UploadedFileName = a.User_Training_Transaction.UploadedFileName, Received_By_Forwarding = a.Received_By_Forwarding, Units_Done = a.Units_Done, Min_Required_Category_Units = a.Min_Required_Category_Units }).AsEnumerable().ToList(); decimal? activityId = userTraining.Select(y => y.Activity_Id).First(); decimal? categoryId = userTraining.Select(y => y.Category_Id).First(); decimal? subactivityId = userTraining.Select(y => y.SubActivity_Id).First(); DateTime?date = userTraining.Select(y => y.Date).First(); //getting hour-units rule to create new hours done according to seleted units IEnumerable <StateActivity__with_Rule2> hourUnits = ctx.StateActivity__with_Rule2 .Include(x => x.Rule2_Master) .Where(x => x.ActivityID == activityId && x.StateID == enrolledStateId); string hourRule = hourUnits.Select(x => x.Rule2_Master.Name).First(); #region Old carried over records ///Getting old carried over record if any so that we can check if ///same carried over record is already is in database so that ///we will update old carried over record or we will create a new one. List <User_Training_Status> oldCarriedOverRecord = ctx.User_Training_Status.Where(x => x.Financial_Year == nextFinancialYear && x.Activity_Id == activityId && x.SubActivity_Id == subactivityId && x.Category_Id == categoryId && x.User_Training_Transaction.Date == date && x.User_Id == user_Id && x.Received_By_Forwarding == "Yes").ToList(); if (oldCarriedOverRecord.Count > 0)//Case to update old carry over record. { decimal statusId = oldCarriedOverRecord.Select(x => x.Id).First(); decimal transactionId = oldCarriedOverRecord.Select(x => x.Training_Transaction_ID).First(); User_Training_Transaction oldCarriedRecord = ctx.User_Training_Transaction.Find(transactionId); User_Training_Status oldCarriedStatusRecord = ctx.User_Training_Status.Find(statusId); //Creating new record i.e carried over record if (hourRule == "1 Unit = 1 Hr") { if (carryOverUnitsList[j].Contains(".5")) { result = "Error - .5 in this category, not allowed"; transaction.Dispose(); rd.Status = "Error"; rd.Message = "*.5 units are not allowed in this category"; rd.Requestkey = "DoCarryOver"; return(rd); } else { oldCarriedRecord.Hours = oldCarriedRecord.Hours + Convert.ToDecimal(carryOverUnitsList[j]); oldCarriedStatusRecord.Units_Done = oldCarriedStatusRecord.Units_Done + Convert.ToDecimal(carryOverUnitsList[j]); hoursRemoved = unitsRemoved = Convert.ToDecimal(carryOverUnitsList[j]); } } if (hourRule == "1 Unit = 2 Hr") { oldCarriedRecord.Hours = oldCarriedRecord.Hours + (Convert.ToDecimal(carryOverUnitsList[j]) * 2); oldCarriedStatusRecord.Units_Done = oldCarriedStatusRecord.Units_Done + Convert.ToDecimal(carryOverUnitsList[j]); hoursRemoved = Convert.ToDecimal(carryOverUnitsList[j]) * 2; unitsRemoved = Convert.ToDecimal(carryOverUnitsList[j]); } ctx.Entry(oldCarriedStatusRecord).State = EntityState.Modified; ctx.SaveChanges(); ctx.Entry(oldCarriedRecord).State = EntityState.Modified; ctx.SaveChanges(); //var allTraningUnitss = ctx.User_Training_Status // .Where(x => x.User_Id == user_Id && x.Financial_Year == financialYear).Select(x => x.Units_Done).Sum(); //if (allTraningUnitss < 10) //{ // result = "Error - minimum"; // transaction.Dispose(); // rd.Status = "Error"; // rd.Message = "Minimum 10 units should be left in this financial year."; // rd.Requestkey = "DoCarryOver"; // return rd; //} //result = "Success"; } #endregion else { //Creating new record i.e carried over record if (hourRule == "1 Unit = 1 Hr") { if (carryOverUnitsList[j].Contains(".5")) { transaction.Dispose(); rd.Status = "Error"; rd.Message = "*.5 units are not allowed in this category"; rd.Requestkey = "DoCarryOver"; return(rd); } else { trainingToCreate.Hours = trainingStatusToCreate.Units_Done = Convert.ToDecimal(carryOverUnitsList[j]); hoursRemoved = unitsRemoved = Convert.ToDecimal(carryOverUnitsList[j]); } } if (hourRule == "1 Unit = 2 Hr") { trainingToCreate.Hours = Convert.ToDecimal(carryOverUnitsList[j]) * 2; trainingStatusToCreate.Units_Done = Convert.ToDecimal(carryOverUnitsList[j]); hoursRemoved = Convert.ToDecimal(carryOverUnitsList[j]) * 2; unitsRemoved = Convert.ToDecimal(carryOverUnitsList[j]); } trainingToCreate.Activity_Id = userTraining.Select(y => y.Activity_Id).First(); trainingToCreate.Category_Id = userTraining.Select(y => y.Category_Id).First(); trainingToCreate.Date = userTraining.Select(y => y.Date).First(); trainingToCreate.Descrption = userTraining.Select(y => y.Descrption).First(); trainingToCreate.Financial_Year = nextFinancialYear; trainingToCreate.Forwardable = null; trainingToCreate.Has_been_Forwarded = null; trainingToCreate.Provider = userTraining.Select(y => y.Provider).First(); trainingToCreate.State_Id = userTraining.Select(y => y.State_Id).First(); trainingToCreate.SubActivity_Id = userTraining.Select(y => y.SubActivity_Id).First(); trainingToCreate.UploadedFile = userTraining.Select(y => y.UploadedFile).First(); trainingToCreate.UploadedFileName = userTraining.Select(y => y.UploadedFileName).First(); trainingToCreate.User_Id = userTraining.Select(y => y.User_Id).First(); trainingToCreate.Your_Role = userTraining.Select(y => y.Your_Role).First(); ctx.User_Training_Transaction.Add(trainingToCreate); ctx.SaveChanges(); decimal newly_inserted_id = trainingToCreate.Id; //New carried over record insertion successful. //Now inserting new carried over record in training_transaction_status trainingStatusToCreate.Activity_Id = userTraining.Select(y => y.Activity_Id).First(); trainingStatusToCreate.Category_Id = userTraining.Select(y => y.Category_Id).First(); trainingStatusToCreate.Financial_Year = nextFinancialYear; trainingStatusToCreate.Min_Required_Category_Units = userTraining.Select(y => y.Min_Required_Category_Units).First(); trainingStatusToCreate.Received_By_Forwarding = "Yes"; trainingStatusToCreate.SubActivity_Id = userTraining.Select(y => y.SubActivity_Id).First(); trainingStatusToCreate.Training_Transaction_ID = newly_inserted_id; trainingStatusToCreate.User_Id = userTraining.Select(y => y.User_Id).First(); ctx.User_Training_Status.Add(trainingStatusToCreate); ctx.SaveChanges(); } //Carried over records insertion over. Now update part. //Editing units and hours of old record to update accordingly. //First User_Training_Transaction User_Training_Transaction utt = ctx.User_Training_Transaction.Find(userTraining.Select(y => y.TrainingTransactionId).First()); utt.Hours = utt.Hours - hoursRemoved; utt.Has_been_Forwarded = "Yes"; ctx.Entry(utt).State = EntityState.Modified; ctx.SaveChanges(); //Now User_Training_Status User_Training_Status uts = ctx.User_Training_Status.Find(userTraining.Select(y => y.TrainingStatusId).First()); uts.Units_Done = uts.Units_Done - unitsRemoved; //if (uts.Units_Done == 0.5m) //{ // transaction.Dispose(); // rd.Status = "Error"; // rd.Message = "Less then minimum allowed units(1) left after this carry over which is not allowed"; // rd.Requestkey = "DoCarryOver"; // return rd; //} ctx.Entry(uts).State = EntityState.Modified; ctx.SaveChanges(); decimal?existedCompletedCategories = ctx.User_Training_Status .Include(x => x.Category_Master).Include(x => x.User_Training_Transaction) .Where(x => x.Category_Id == uts.Category_Id && x.Financial_Year == financialYear && x.User_Id == user_Id).Select(x => x.Units_Done).Sum(); if (existedCompletedCategories < 1) { result = "Error - minimum"; transaction.Dispose(); rd.Status = "Error"; rd.Message = "Less then minimum allowed units(i.e 1) left after this carry over which is not allowed"; rd.Requestkey = "DoCarryOver"; return(rd); } var allTraningUnitss = ctx.User_Training_Status .Where(x => x.User_Id == user_Id && x.Financial_Year == financialYear).Select(x => x.Units_Done).Sum(); if (allTraningUnitss < 10) { result = "Error - minimum"; transaction.Dispose(); rd.Status = "Error"; rd.Message = "Minimum 10 units should be left in this financial year."; rd.Requestkey = "DoCarryOver"; return(rd); } result = "Success"; } transaction.Commit(); rd.Status = "Success"; rd.Message = "Selected units are carried over successfully."; rd.Requestkey = "DoCarryOver"; return(rd); } } } catch (Exception ee) { rd.Status = "Error"; rd.Message = "Something went wrong." + ee.ToString(); rd.Requestkey = "DoCarryOver"; return(rd); } }
public Return UpdateUserProfile(string id, string firstName, string lastName, string otherName, string streetName, string postCode, string suburb, string stateId, string countryId, string lawSocietyNumber, string streetNumber, string phoneNumber, string Password, string address, string firm) { Return rd = new Return(); try { if (id == string.Empty) { rd.Status = "Failure"; rd.Message = "User id is required"; rd.Requestkey = "UpdateUserProfile"; return(rd); } if (true) { } decimal userId = Convert.ToDecimal(id); var user = db.User_Profile.Where(u => u.ID == userId).FirstOrDefault(); if (user == null) { rd.Status = "Failure"; rd.Message = "User not found"; rd.Requestkey = "UpdateUserProfile"; return(rd); } if (firstName != string.Empty) { user.FirstName = firstName; } else { rd.Message = "First name is required."; rd.Status = "Failure"; rd.Requestkey = "UpdateUserProfile"; return(rd); } if (lastName != string.Empty) { user.LastName = lastName; } else { rd.Message = "Last name is required."; rd.Status = "Failure"; rd.Requestkey = "UpdateUserProfile"; return(rd); } if (otherName != string.Empty) { user.OtherName = otherName; } if (streetName != string.Empty) { user.StreetName = streetName; } else { rd.Message = "Street name is required."; rd.Status = "Failure"; rd.Requestkey = "UpdateUserProfile"; return(rd); } if (streetNumber != string.Empty) { user.StreetNumber = streetNumber; } else { rd.Message = "Street number is required."; rd.Status = "Failure"; rd.Requestkey = "UpdateUserProfile"; return(rd); } if (postCode != string.Empty) { if (postCode.ToString().Length <= 0 || postCode.ToString().Length > 4) { rd.Message = "Invalid Post Code"; rd.Status = "Failure"; rd.Requestkey = "UpdateUserProfile"; return(rd); } if (NewClass.ContainsAny(postCode.ToString(), specialCharacterList)) { rd.Message = "Invalid Post Code"; rd.Status = "Failure"; rd.Requestkey = "UpdateUserProfile"; return(rd); } user.PostCode = Convert.ToDecimal(postCode); } else { rd.Message = "Post code is required."; rd.Status = "Failure"; rd.Requestkey = "UpdateUserProfile"; return(rd); } if (suburb != string.Empty) { user.Suburb = suburb; } if (stateId != string.Empty) { user.StateID = Convert.ToDecimal(stateId); } else { rd.Message = "State name is required."; rd.Status = "Failure"; rd.Requestkey = "UpdateUserProfile"; return(rd); } if (countryId != string.Empty) { user.CountryID = Convert.ToDecimal(countryId); } else { rd.Message = "Country name is required."; rd.Status = "Failure"; rd.Requestkey = "UpdateUserProfile"; return(rd); } if (lawSocietyNumber != string.Empty) { if (lawSocietyNumber.ToString().Length < 5 || lawSocietyNumber.ToString().Length > 10) { rd.Message = "Invalid LawSociety Number"; rd.Status = "Failure"; rd.Requestkey = "UpdateUserProfile"; return(rd); } if (NewClass.ContainsAny(lawSocietyNumber.ToString(), specialCharacterList)) { rd.Message = "Invalid LawSociety Number"; rd.Status = "Failure"; rd.Requestkey = "UpdateUserProfile"; return(rd); } user.LawSocietyNumber = Convert.ToDecimal(lawSocietyNumber); } else { rd.Message = "Law society number is required."; rd.Status = "Failure"; rd.Requestkey = "UpdateUserProfile"; return(rd); } if (phoneNumber != string.Empty) { if (phoneNumber.ToString().Length < 10 || phoneNumber.ToString().Length > 10) { rd.Message = "Invalid Phone Number"; rd.Status = "Failure"; rd.Requestkey = "UpdateUserProfile"; return(rd); } user.PhoneNumber = phoneNumber; } else { rd.Message = "Phone number is required."; rd.Status = "Failure"; rd.Requestkey = "UpdateUserProfile"; return(rd); } if (Password != string.Empty) { user.Password = Password; } else { rd.Message = "Password is required."; rd.Status = "Failure"; rd.Requestkey = "UpdateUserProfile"; return(rd); } if (address != string.Empty) { user.Address = address; } if (firm != string.Empty) { user.Firm = firm; } db.Entry(user).State = EntityState.Modified; db.SaveChanges(); var userProfile = db.User_Profile.Where(u => u.ID == userId).FirstOrDefault(); UserProfile up = new UserProfile(); up.ID = userProfile.ID; up.FirstName = userProfile.FirstName; up.LastName = userProfile.LastName; up.OtherName = userProfile.OtherName; up.StreetNumber = userProfile.StreetNumber; up.StreetName = userProfile.StreetName; up.PostCode = userProfile.PostCode; up.Suburb = userProfile.Suburb; up.StateID = userProfile.StateID; up.StateName = userProfile.State_Master.Name; up.CountryID = userProfile.CountryID; up.CountryName = userProfile.Country_Master.Name; up.StateEnrolled = userProfile.StateEnrolled; up.StateEnrolledName = userProfile.State_Master1.Name; up.StateEnrolledShortName = userProfile.State_Master1.ShortName; up.LawSocietyNumber = userProfile.LawSocietyNumber; up.EmailAddress = userProfile.EmailAddress; up.Password = userProfile.Password; up.PhoneNumber = userProfile.PhoneNumber; up.Date = userProfile.Date; up.Address = userProfile.Address; up.Device_Imei = userProfile.Device_Imei; up.Device_Token = userProfile.Device_Token; up.Device_Type = userProfile.Device_Type; up.Firm = userProfile.Firm; rd.Status = "Success"; rd.Message = "Profile updated successfully"; rd.Requestkey = "UpdateUserProfile"; rd.userProfile = up; return(rd); } catch (DbEntityValidationException e) { string errorMessage = string.Empty; foreach (DbEntityValidationResult 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 (DbValidationError ve in eve.ValidationErrors) { //Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", // ve.PropertyName, ve.ErrorMessage); errorMessage = ve.ErrorMessage; rd.Message = rd.Message + ", " + errorMessage; } } rd.Status = "Failure"; rd.Requestkey = "UpdateUserProfile"; return(rd); } catch (Exception) { rd.Status = "Failure"; rd.Message = "Something went wrong. Please try after some time."; rd.Requestkey = "UpdateUserProfile"; return(rd); } }
public ReturnData PostTransaction(string email, string Plan_ID, string payerId, string Rate_Id, string paymentId, string Amount, string Transection_ID) { ReturnData rd = new ReturnData(); if (email == string.Empty || Plan_ID == string.Empty || payerId == string.Empty || paymentId == string.Empty || Rate_Id == string.Empty || Amount == string.Empty || Transection_ID == string.Empty) { rd.Status = "Failure"; rd.Message = "Missing Parameters"; rd.Requestkey = "PostTransactions"; return(rd); } try { decimal userId = db.User_Profile.Where(x => x.EmailAddress == email).Select(x => x.ID).First(); //-----For sending Invoice mail------ decimal recordId = 0; decimal planId = Convert.ToDecimal(Plan_ID); using (LaxNarroEntities ctx = new LaxNarroEntities()) { using (var transaction = ctx.Database.BeginTransaction()) { int?maxInvoice = ctx.User_Transaction_Master.Max(u => u.Invoice_No); Rate_Card rate_card = ctx.Rate_Card.Include(x => x.Plan_Master) .Where(m => m.Plan_Id == planId && m.Status == "Active" && m.Plan_Master.Plan != "Demo").FirstOrDefault(); if (rate_card == null) { rd.Status = "Failure"; rd.Message = "Invalid Plan (Demo)"; rd.Requestkey = "PostTransactions"; return(rd); } //if(rate_card.Amount !=Convert.ToDecimal(Amount)) //{ // PaypalResponse paypalResponse1 = new PaypalResponse // { // user_id = userId, // Paypal_ReferenceId = paymentId, // intent = "sale", // payer = "Android", // payee = string.Empty, // note_to_payer = "From Android", // update_time = Convert.ToString(DateTime.Today), // create_time = Convert.ToString(DateTime.Today), // response_state = "created", // failure_reason = "Invalid Amount" // }; // ctx.PaypalResponses.Add(paypalResponse1); // ctx.SaveChanges(); // transaction.Commit(); // rd.Status = "Failure"; // rd.Message = "Invalid Amount"; // rd.Requestkey = "PostTransactions"; // return rd; //} User_Transaction_Master userTransaction = new User_Transaction_Master(); List <User_Transaction_Master> userAllTransaction = ctx.User_Transaction_Master .Where(x => x.User_ID == userId).ToList(); // Set the payer for the payment var paymentExecution = new PaymentExecution() { payer_id = payerId }; // Identify the payment to execute var payment = new Payment() { id = paymentId }; //var apiContext = GetAPIContext(); // Execute the Payment //var executedPayment = payment.Execute(apiContext, paymentExecution); int?max = userAllTransaction.Max(u => (int?)u.Invoice_No); User_Transaction_Master maxedInvoicedTransaction = userAllTransaction .FirstOrDefault(x => x.User_ID == userId && x.Invoice_No == max); int?maxedInvoiceNo = ctx.User_Transaction_Master.Max(u => (int?)u.Invoice_No); //if (executedPayment.state == "approved") //{ //---------For new payment record (second time payment and so on)------- if (maxedInvoicedTransaction.Payment_Status != "N/A") { userTransaction.Amount = Convert.ToDecimal(rate_card.Amount); DateTime?endDate = maxedInvoicedTransaction.End_Date; string strEndDate = string.Empty; if (endDate != null) { strEndDate = endDate.ToString(); } userTransaction.Start_Date = Convert.ToDateTime(strEndDate); if (rate_card.Plan_Master.Plan == "Yearly") { userTransaction.End_Date = userTransaction.Start_Date.AddYears(1); } else { userTransaction.End_Date = userTransaction.Start_Date.AddYears(2); } if (maxInvoice == null) { userTransaction.Invoice_No = 1; } else { userTransaction.Invoice_No = maxInvoice + 1; } userTransaction.Payment_Date = DateTime.Today; userTransaction.Payment_Method = "Online"; userTransaction.Payment_Status = "Paid"; userTransaction.Paypal_PayerId = payerId; userTransaction.PlanID = rate_card.Plan_Id; userTransaction.Rate_ID = rate_card.Rate_Id; userTransaction.Status = "Active"; userTransaction.Transaction_Status = "approved"; userTransaction.Transection_ID = Transection_ID; userTransaction.User_ID = userId; ctx.User_Transaction_Master.Add(userTransaction); ctx.SaveChanges(); recordId = userTransaction.Id; rd.Status = "Success"; rd.Message = "Transaction Saved"; rd.Requestkey = "PostTransactions"; //return rd; } //---------For updating the demo record (First time payment)------- else { maxedInvoicedTransaction.Amount = Convert.ToDecimal(rate_card.Amount); if (rate_card.Plan_Master.Plan == "Yearly") { maxedInvoicedTransaction.End_Date = DateTime.Today.AddYears(1); } else { maxedInvoicedTransaction.End_Date = DateTime.Today.AddYears(2); } if (maxInvoice == null) { maxedInvoicedTransaction.Invoice_No = 1; } else { maxedInvoicedTransaction.Invoice_No = maxInvoice + 1; } maxedInvoicedTransaction.Payment_Date = DateTime.Today; maxedInvoicedTransaction.Payment_Method = "Online"; maxedInvoicedTransaction.Payment_Status = "Paid"; maxedInvoicedTransaction.Paypal_PayerId = payerId; maxedInvoicedTransaction.PlanID = rate_card.Plan_Id; maxedInvoicedTransaction.Rate_ID = rate_card.Rate_Id; //DateTime? endDate = maxedInvoicedTransaction.End_Date; //string strEndDate = string.Empty; //if (endDate != null) // strEndDate = endDate.ToString(); maxedInvoicedTransaction.Start_Date = DateTime.Today; maxedInvoicedTransaction.Status = "Active"; maxedInvoicedTransaction.Transaction_Status = "approved"; maxedInvoicedTransaction.Transection_ID = Transection_ID; maxedInvoicedTransaction.User_ID = userId; ctx.Entry(maxedInvoicedTransaction).State = EntityState.Modified; ctx.SaveChanges(); recordId = maxedInvoicedTransaction.Id; rd.Status = "Success"; rd.Message = "Transaction Saved"; rd.Requestkey = "PostTransactions"; //return rd; } PaypalResponse paypalResponse = new PaypalResponse { user_id = userId, Paypal_ReferenceId = paymentId, intent = "sale", payer = "Android", payee = string.Empty, note_to_payer = "From Android", update_time = Convert.ToString(DateTime.Today), create_time = Convert.ToString(DateTime.Today), response_state = "approved", failure_reason = string.Empty }; ctx.PaypalResponses.Add(paypalResponse); ctx.SaveChanges(); MailLog user = ctx.MailLogs.FirstOrDefault(x => x.UserID == userId); if (user != null) { user.LastReminderStatus = "Deactive"; ctx.SaveChanges(); } transaction.Commit(); } Thread thread = new Thread(() => SendInvoice(recordId, userId)); thread.Start(); User_Profile userMail = ctx.User_Profile.Where(p => p.ID == userId).FirstOrDefault(); Thread thread2 = new Thread(() => SendMail(userMail.FirstName, userMail.LastName, userMail.EmailAddress, "", "Lexnarro - Subscription Successful", "~/EmailTemplate/SubscriptionMail.html")); thread2.Start(); return(rd); } } //catch (DbEntityValidationException e) //{ // string errorMessage = string.Empty; // foreach (DbEntityValidationResult 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 (DbValidationError ve in eve.ValidationErrors) // { // Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", // ve.PropertyName, ve.ErrorMessage); // errorMessage = ve.ErrorMessage; // //TempData["message"] = ViewBag.message + ToasterMessage.Message(ToastType.error, errorMessage); // } // } //} catch (Exception r) { rd.Status = "Failure"; rd.Message = "Something went wrong. Please contact administrator"; rd.Requestkey = "PostTransactions"; return(rd); } }
public ActionResult Edit([Bind(Include = "Id,StateID,Total_Units,Start_Date,End_Date")] Total_Unit_Master total_Unit_Master) { try { //if (ModelState.IsValid) //{ ViewBag.StateID = new SelectList(db.State_Master.OrderBy(m => m.Name), "ID", "Name", total_Unit_Master.StateID); if (total_Unit_Master.Start_Date > total_Unit_Master.End_Date) { ViewBag.message = ToasterMessage.Message(ToastType.info, "End date should be greater then start date"); return(View()); } else { List <Total_Unit_Master> getName = db.Total_Unit_Master.Where(u => u.StateID == total_Unit_Master.StateID && u.Total_Units == total_Unit_Master.Total_Units && u.Start_Date == total_Unit_Master.Start_Date && u.End_Date == total_Unit_Master.End_Date && u.Id != total_Unit_Master.Id).ToList(); if (getName.Count > 0) { ViewBag.message = ToasterMessage.Message(ToastType.info, "Record already exist"); return(View()); } else { db.Entry(total_Unit_Master).State = EntityState.Modified; db.SaveChanges(); TempData["message"] = ToasterMessage.Message(ToastType.success, "Updated Successfully"); return(RedirectToAction("Index")); } } //} } catch (DbEntityValidationException e) { string errorMessage = string.Empty; foreach (DbEntityValidationResult 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 (DbValidationError ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); errorMessage = ve.ErrorMessage; ViewBag.message = ViewBag.message + ToasterMessage.Message(ToastType.error, errorMessage); } } return(View()); } catch (Exception) { ViewBag.message = ToasterMessage.Message(ToastType.error, "Something went wrong"); } return(View()); }
private void CheckSubscriptionStatusAndDoStuff() { try { using (LaxNarroEntities ctx = new LaxNarroEntities()) { DateTime dt = DateTime.Today; var expiredPlanUsers = (from s in db.ExpiredPlanUserMailLogs where s.NextReminderDueDate <= dt select s).ToList(); User_Transaction_Master userTransaction = db.User_Transaction_Master.Include(u => u.User_Profile). Include(u => u.Rate_Card).Include(u => u.Plan_Master).Where(u => u.Id == expiredPlanUsers[0].UserID).SingleOrDefault(); for (int i = 0; i < expiredPlanUsers.Count; i++) { switch (expiredPlanUsers[i].ReminderType) { case "N/A": // Write Code to Sent Reminder One. //________________________________ expiredPlanUsers[i].UserID = expiredPlanUsers[i].UserID; expiredPlanUsers[i].ReminderType = "First"; expiredPlanUsers[i].ReminderDate = dt; expiredPlanUsers[i].ReminderStatus = "Sent"; expiredPlanUsers[i].NextReminderDueDate = Convert.ToDateTime(expiredPlanUsers[i].NextReminderDueDate).AddMonths(5); expiredPlanUsers[i].RecordOperationDate = dt; db.Entry(expiredPlanUsers[i]).State = EntityState.Modified; db.SaveChanges(); SendResubMail(userTransaction.User_Profile.FirstName, userTransaction.User_Profile.LastName, userTransaction.User_Profile.EmailAddress, userTransaction.User_ID, userTransaction.End_Date, "~/EmailTemplate/ResubscriptionMail.html"); break; case "First": // Write Code to Sent Reminder Two. //________________________________ expiredPlanUsers[i].UserID = expiredPlanUsers[i].UserID; expiredPlanUsers[i].ReminderType = "Second"; expiredPlanUsers[i].ReminderDate = dt; expiredPlanUsers[i].ReminderStatus = "Sent"; expiredPlanUsers[i].NextReminderDueDate = Convert.ToDateTime(expiredPlanUsers[i].NextReminderDueDate).AddMonths(1).AddDays(-1); expiredPlanUsers[i].RecordOperationDate = dt; db.Entry(expiredPlanUsers[i]).State = EntityState.Modified; db.SaveChanges(); SendResubMail(userTransaction.User_Profile.FirstName, userTransaction.User_Profile.LastName, userTransaction.User_Profile.EmailAddress, userTransaction.User_ID, userTransaction.End_Date, "~/EmailTemplate/ResubscriptionMail.html"); break; } } } } catch (Exception r) { //throw; } }