public UserPlanModel InsertUserPlan(UserPlanModel planModel) { //unitOfWork.StartTransaction(); UserPlanRepository repo = new UserPlanRepository(unitOfWork); //UserLocationModel userLocationModel = new UserLocationModel(); UserPlan userPlan = new UserPlan(); AutoMapper.Mapper.Map(planModel, userPlan); userPlan = repo.Insert(userPlan); //unitOfWork.Commit(); AutoMapper.Mapper.Map(userPlan, planModel); return planModel; }
public UserPlanModel GetUserPlanByUserId(string userId) { //unitOfWork.StartTransaction(); UserPlanRepository repo = new UserPlanRepository(unitOfWork); UserPlanModel userPlanModel = new UserPlanModel(); UserPlan userPlan = new UserPlan(); userPlan = repo.GetAll().Where(x=>x.UserId==userId && x.ExpiredDate > DateTime.UtcNow).FirstOrDefault(); //if (userPlan == null) //{ // UserPlan checkPlan = new UserPlan(); // checkPlan = repo.GetAll().Where(x => x.UserId == userId).FirstOrDefault(); // repo.Delete(x=>x.Id== checkPlan.Id); //} //unitOfWork.Commit(); AutoMapper.Mapper.Map(userPlan, userPlanModel); return userPlanModel; }
public IHttpActionResult ReturnSucceesCallback(TransactionHistoryModel model) { try { //string headers = string.Empty; //foreach (var head in Request.Content.Headers) //{ // headers += "Key : " + head.Key + " , Value : " + head.Value; //} //string parameters = string.Empty; //foreach (var param in HttpContext.Current.Request.Params) //{ var merchantRefrence = model.MerchantReference; TransactionHistoryModel historyModel = new TransactionHistoryModel(); historyModel = transactionHistoryService.FindTransactionHistoryByMerchantRegrence(merchantRefrence); historyModel.Status = model.Status; historyModel.ResponseMessage = model.ResponseMessage; historyModel.Eci = model.Eci; historyModel.CardNumber = model.CardNumber; historyModel.FortId = model.FortId; historyModel.ResponseCode = model.ResponseCode; historyModel.CustomerEmail = model.CustomerEmail; historyModel.CustomerIp = model.CustomerIp; //historyModel.Amount = model.Amount; historyModel.Command = model.Command; historyModel.PaymentOption = model.PaymentOption; historyModel.ExpiryDate = model.ExpiryDate; historyModel.Signature = model.Signature; if (historyModel.URFXPaymentType == URFXPaymentType.PlanPayment) { if (historyModel.Status == Utility.Constants.SUCCESS_STATUS) { var startDate = DateTime.Now; UserPlanModel userPlanModel = new UserPlanModel(); userPlanModel.PlanId = historyModel.PlanId; userPlanModel.UserId = historyModel.UserId; userPlanModel.NumberOfTeams = historyModel.NumberOfTeams; userPlanModel.CreatedDate = startDate; userPlanModel.ExpiredDate = startDate.AddDays(30); bool planExist = userPlanService.CheckExistanceOfUserPlan(userPlanModel.UserId); if (!planExist) { userPlanModel = userPlanService.InsertUserPlan(userPlanModel); } transactionHistoryService.UpdateTransactionHistory(historyModel); //parameters += "Key : " + param + " , value:" + HttpContext.Current.Request.Params[param.ToString()]; } else { transactionHistoryService.UpdateTransactionHistory(historyModel); } } else if(historyModel.URFXPaymentType == URFXPaymentType.JobPayment) { ApplicationUser user = UserManager.FindById(historyModel.UserId); transactionHistoryService.UpdateTransactionHistory(historyModel); JobModel jobModel = new JobModel(); if (historyModel.Status == Utility.Constants.SUCCESS_STATUS) { jobModel = jobService.GetJobById(historyModel.JobId); jobModel.IsPaid = true; jobModel.CreatedDate = DateTime.UtcNow; jobService.UpadteJob(jobModel); } if (user.DeviceType == Utility.Constants.DEVICE_TYPE_ANDROID) { string postData = "collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.userId=" + historyModel.UserId + "&data.jobId=" + historyModel.JobId + "&data.type=" + Utility.Constants.JOB_CREATED_TYPE + "&data.message=" + Utility.Constants.MESSAGE_FOR_JOB_CREATED + "&data.time=" + System.DateTime.Now.ToString() + "®istration_id=" + user.DeviceToken + ""; var response = sendNotificationService.SendNotificationForAndroid(postData); } else if (user.DeviceType == Utility.Constants.DEVICE_TYPE_IOS) { string payload = "{\"aps\":{\"alert\":\"" + "Hi, " + Utility.Constants.MESSAGE_FOR_JOB_CREATED + "" + "\",\"badge\":1,\"sound\":\"default\"},\"JobId\":" + historyModel.JobId + ",\"userId\":\"" + historyModel.UserId + "\",\"type\":\"" + Utility.Constants.JOB_CREATED_TYPE + "\"}"; sendNotificationService.SendNotificationForIOS(user.DeviceToken, payload); } } else { ApplicationUser user = UserManager.FindById(historyModel.UserId); transactionHistoryService.UpdateTransactionHistory(historyModel); if (user.DeviceType == Utility.Constants.DEVICE_TYPE_ANDROID) { string postData = "collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.userId=" + historyModel.UserId + "&data.jobId=" + historyModel.JobId + "&data.type=" + Utility.Constants.ADD_ADDITIONAL_TYPE + "&data.message=" + Utility.Constants.MESSAGE_FOR_ADD_ADDITIONAL + "&data.time=" + System.DateTime.Now.ToString() + "®istration_id=" + user.DeviceToken + ""; var response = sendNotificationService.SendNotificationForAndroid(postData); } else if (user.DeviceType == Utility.Constants.DEVICE_TYPE_IOS) { string payload = "{\"aps\":{\"alert\":\"" + "Hi, " + Utility.Constants.MESSAGE_FOR_ADD_ADDITIONAL + "" + "\",\"badge\":1,\"sound\":\"default\"},\"JobId\":" + historyModel.JobId + ",\"userId\":\"" + historyModel.UserId + "\",\"type\":\"" + Utility.Constants.ADD_ADDITIONAL_TYPE + "\"}"; sendNotificationService.SendNotificationForIOS(user.DeviceToken, payload); } } // parameters += "Key : " + param + " , value:" + HttpContext.Current.Request.Params[param.ToString()]; // } // System.IO.File.WriteAllText(HttpContext.Current.Server.MapPath("~/ExceptionFile.txt"), headers + parameters); return Ok(historyModel); } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); System.IO.File.WriteAllText(HttpContext.Current.Server.MapPath("~/ExceptionFile.txt"), ex.Message); return Ok(); } }
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { var userManager = context.OwinContext.GetUserManager<ApplicationUserManager>(); try { ApplicationUser user = await userManager.FindAsync(context.UserName, context.Password); if (user != null) { var roles = await userManager.GetRolesAsync(user.Id); // Get all roles of user from server var role = roles.FirstOrDefault(); // Get user role var IsEmployee = HttpContext.Current.Request.Headers["IsEmployee"]; var IsClient = HttpContext.Current.Request.Headers["IsClient"]; if (IsEmployee == null && role == URFXRoles.Employee.ToString()) { context.SetError("invalid_grant", "You are not authorised to login.Please contact at [email protected]"); return; } if (IsClient == null && role == URFXRoles.Client.ToString()) { context.SetError("invalid_grant", "You are not authorised to login.Please contact at [email protected]"); return; } if (role != null && role != URFXRoles.Employee.ToString()) { if (user.RegistrationType == RegistrationType.Simple) { if (!user.EmailConfirmed) { context.SetError("invalid_grant", "Please confirm your email first."); return; } } } if (role != URFXRoles.Client.ToString()) { var deviceType = HttpContext.Current.Request.Headers["deviceType"]; var deviceToken = HttpContext.Current.Request.Headers["deviceToken"]; user.DeviceToken = deviceToken; user.DeviceType = deviceType; } IdentityResult result = await UserManager.UpdateAsync(user); ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(userManager, OAuthDefaults.AuthenticationType); ClaimsIdentity cookiesIdentity = await user.GenerateUserIdentityAsync(userManager, CookieAuthenticationDefaults.AuthenticationType); UserPlanModel userPlanModel = new UserPlanModel(); ServiceProviderModel serviceproviderModel = new ServiceProviderModel(); userPlanModel = userPlanService.GetUserPlanByUserId(user.Id); if (role == URFXRoles.ServiceProvider.ToString()) { serviceproviderModel = serviceProviderService.GetServiceProviderById(user.Id); } AuthenticationProperties properties = null; if (user.DeviceType != null && user.DeviceToken != null) { properties = CreateProperties(user.UserName, role, user.Id, user.DeviceType, user.DeviceToken, userPlanModel.PlanId, user.IsRegister, user.IsLogin, serviceproviderModel.ServiceProviderType); } else { properties = CreateProperties(user.UserName, role, user.Id, userPlanModel.PlanId, user.IsRegister, user.IsLogin, serviceproviderModel.ServiceProviderType); } AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties); context.Validated(ticket); context.Request.Context.Authentication.SignIn(cookiesIdentity); } else { context.SetError("invalid_grant", "The user name or password is incorrect."); return; } } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); } }