public IHttpActionResult UpdateFlag(RentoRequest <UpdateUserFlagRequest> request) { Logger.Debug("User - UpdateFlag", request); var response = new RentoResponse(request); return(Ok(TryCatch(request, response, ValidateType.Operation, async() => { if (!ValidateRequirdField(request.Data.UserId)) { response.ErrorCode = ErrorCode.RequirdField; return; } var userType = await UserManager.UpdateFlag(request.Data); RentoCache.Set(request.Data.UserId.ToString(), (byte)userType); }))); }
public IHttpActionResult ListOrderAction(RentoRequest <int> request) { var response = new RentoResponse <OrderAction>(request); return(Ok(TryCatch(request, response, ValidateType.Operation, async() => { if (!ValidateRequirdField(request.PageNumber)) { response.ErrorCode = ErrorCode.RequirdField; return; } ; var rowsCount = 0; response.Data = await CarManager.ListOrderAction(request.Data); response.RowsCount = rowsCount; }))); }
public IHttpActionResult SaveExternal(RentoRequest <LookUp <int> > request) { var response = new RentoResponse <Entity.BaseEntity>(request); return(Ok(TryCatch(request, response, ValidateType.Admin, async() => { if (!ValidateRequirdField(request.Data.Name, request.Data.NameEn) || !ValidateRequirdField(request.Data.ExternalData) ) { response.ErrorCode = ErrorCode.RequirdField; return; } ; response.Data = await Database.LookUpManager.Save <int>(UserSession.Id, request.Data); }))); }
public IHttpActionResult ListOrder(RentoRequest <int> request) { var response = new RentoResponse <List <Order> >(request); return(Ok(TryCatch(request, response, ValidateType.Active, async() => { if (!ValidateRequirdField(request.PageNumber)) { response.ErrorCode = ErrorCode.RequirdField; return; } ; var temp = await CarManager.ListOrder((UserType)UserSession.Type == UserType.Operation ? 0 : UserSession.Id, request.PageNumber, Constant.PAGE_SIZE, request.Data); response.RowsCount = temp.RowsCount; response.Data = temp.Data; }))); }
public IHttpActionResult Create(RentoRequest <OfferCreate> request) { var response = new RentoResponse <BaseEntity>(request); return(Ok(TryCatch(request, response, ValidateType.Active, async() => { if (!ValidateRequirdField(request.Data.CarId, request.Data.Cost, request.Data.Discount) || !ValidateRequirdField(request.Data.From, request.Data.To) ) { response.ErrorCode = ErrorCode.RequirdField; return; } ; response.Data = await Database.OfferManager.Create(UserSession.Id, request.Data); }))); }
public IHttpActionResult GetTermsAndCondition(RentoRequest <int> request) { var response = new RentoResponse <string>(request); return(Ok(TryCatch(request, response, ValidateType.None, async() => { if (request.Data == 0) { if (request.Language == (int)Language.English) { response.Data = ReadFileFromAppData("termsEn"); } response.Data = ReadFileFromAppData("termsAr"); } response.Data = await Database.UserManager.GetGetTermsAndCondition(request.Data); }))); }
public IHttpActionResult UserList(RentoRequest <CarListRequest> request) { Logger.Debug("Car - UserList", request); var response = new RentoResponse <List <CarBaseInfo> >(request); return(Ok(TryCatch(request, response, ValidateType.Active, async() => { if (request.Data != null && !ValidateRequirdField(request.Data.CityId)) { response.ErrorCode = ErrorCode.RequirdField; return; } var tempResponse = await CarManager.List(UserSession.Id, request.Data); response.Data = tempResponse.Data; response.RowsCount = tempResponse.RowsCount; }))); }
public IHttpActionResult List(RentoRequest <CarListRequest> request) { Logger.Debug("Car - List", request); var response = new RentoResponse <List <CarBaseInfo> >(request); return(Ok(TryCatch(request, response, ValidateType.None, async() => { var userType = UserType.Active; var reult = await ValidateRequst(request); if (!string.IsNullOrEmpty(request.Token) && reult.Key) { userType = (UserType)UserSession.Type; } var tempReponse = await CarManager.List(0, request.Data, request.PageNumber, Constant.PAGE_SIZE, userType); response.RowsCount = tempReponse.RowsCount; response.Data = tempReponse.Data; }))); }
public IHttpActionResult ResendCode(RentoRequest request) { Logger.Debug("ResendCode", request); var response = new RentoResponse(request); return(Ok(TryCatch(request, response, ValidateType.Pending, async delegate() { var mobileNumber = await AccountManager.SelectMobile(UserSession.Id); if (!string.IsNullOrEmpty(mobileNumber)) { var lastCache = RentoCache.Get <int>(RESEND_CODE_KEY + mobileNumber); if (lastCache == 0) { lastCache = 1; } if (lastCache > 3) { response.ErrorCode = ErrorCode.GeneralError; } else { RentoCache.Set(RESEND_CODE_KEY + mobileNumber, lastCache++); RentoCache.Set(mobileNumber, 1); var code = StringHelper.GenerateRandomNumber(4); Logger.Debug("Send Code Resend", new { Code = code, Mobile = mobileNumber }); RunActionAsync(() => { SMSMessage.Send(mobileNumber, string.Format("Your Verification Code is: {0}", code)); }); RentoCache.Set(VERIFICATION_KEY + request.Token, new ForgetPasswordCacheObject() { Code = code, UserId = UserSession.Id }, 1); } } }))); }
public IHttpActionResult Checkout(RentoRequest <Checkout> request) { Logger.Debug("Checkout", request); var response = new RentoResponse <int>(request); return(Ok(TryCatch(request, response, ValidateType.Active, async() => { var daysPeriod = (request.Data.To - request.Data.From).Days; if (!ValidateRequirdField(request.Data.CarId, request.Data.Price) || !ValidateRequirdField(request.Data.From, request.Data.To) || (daysPeriod < 1) || (request.Data.Flag == (int)CheckoutFlag.DeliverToMyLocation && (request.Data.Location == null || !ValidateRequirdField(request.Data.Location.Longitude, request.Data.Location.Latitude)))) { response.ErrorCode = ErrorCode.RequirdField; return; } var checkOutId = await CarManager.Checkout(UserSession.Id, request.Data); switch (checkOutId) { case -1: response.ErrorCode = ErrorCode.CustomerNonComplete; return; case 0: response.ErrorCode = ErrorCode.CarAlreadyReserved; return; default: await Database.MessageManager.Create(UserSession.Id, string.Format("{0} {1}", request.Language == (int)Language.Arabic ? "تم ارسال طلب استئجار سيارة من قبلكم بنجاح ورقم الحجر هو" : "Car rent order request done successfully with number", checkOutId )); break; } response.Data = checkOutId; }))); }
public IHttpActionResult GetUserInfo(RentoRequest <int> request) { Logger.Debug("User - GetUserInfo", request); var response = new RentoResponse <User>(request); return(Ok(TryCatch(request, response, ValidateType.Active, async() => { if (request.Data == 0) { request.Data = UserSession.Id; } else { if ((UserType)UserSession.Type != UserType.Operation && (UserType)UserSession.Type != UserType.Administrator) { response.ErrorCode = ErrorCode.AccessDenai; return; } } response.Data = await AccountManager.Select(request.Data); }))); }
public async Task <ActionResult> Details(int id) { RentoResponse <Car> carInfoResponse = null; try { carInfoResponse = await CallApi <int, Car>("Car/Get", id); if (carInfoResponse.ErrorCode != ErrorCode.Success) { return(RedirectToAction("Index")); } ViewBag.Type = FixData.SYSTEM_TYPE; ViewBag.ModelSubType = FixData.SYSTEM_SUB_TYPE.Where(c => c.ExternalData == 1); ViewBag.SubType = FixData.SYSTEM_SUB_TYPE; } catch (Exception e) { Logger.Exception(e); } return(View(carInfoResponse.Data)); }
public IHttpActionResult CloseBooking(RentoRequest <CloseBooking> request) { Logger.Debug("CloseBooking", request); var response = new RentoResponse(request); return(Ok(TryCatch(request, response, ValidateType.Active, async() => { if (!ValidateRequirdField(request.Data.CheckoutId) || !ValidateRequirdField(request.Data.Star) || (request.Data.Flag == (int)CheckoutFlag.Rejected && !ValidateRequirdField(request.Data.Comment))) { response.ErrorCode = ErrorCode.RequirdField; return; } if (request.Data.Flag == (int)CheckoutFlag.GetFromOffice || request.Data.Flag == (int)CheckoutFlag.Rejected) { request.Data.Flag = (int)CheckoutFlag.CustomerRejected; } await CarManager.CloseBooking(UserSession.Id, request.Data); }))); }
public IHttpActionResult Create(RentoRequest <UserLogin> request) { Logger.Debug("User - Create", request); var response = new RentoResponse(request); return(Ok(TryCatch(request, response, ValidateType.Operation, async() => { if (!ValidateRequirdField(request.Data.Username, request.Data.Password)) { response.ErrorCode = ErrorCode.RequirdField; return; } if (!request.Data.Password.CheckRegexValid(Constant.PASSWORD_EXPRESION)) { response.ErrorCode = ErrorCode.InvalidPasswordFormat; return; } var userId = await Database.UserManager.Create(request.Data); if (userId == 0) { response.ErrorCode = ErrorCode.UsernameAlreadyExists; } }))); }
protected async Task <RentoResponse> TryCatchSyncBase(RentoRequest request, ValidateType validateType, Action <RentoResponse> process) { var response = new RentoResponse(request); try { bool valid = true; switch (validateType) { case ValidateType.Active: var validate = await ValidateRequst(request); if (!validate.Key) { response.ErrorCode = validate.Value; valid = false; } break; case ValidateType.Pending: validate = await ValidateRequst(request, true); if (!validate.Key) { response.ErrorCode = validate.Value; valid = false; } break; case ValidateType.Operation: valid = await ValidateRequstOperation(request); if (!valid) { response.ErrorCode = ErrorCode.AccessDenai; } break; case ValidateType.Admin: valid = await ValidateRequstAdmin(request); if (!valid) { response.ErrorCode = ErrorCode.AccessDenai; } break; case ValidateType.Block: validate = await ValidateRequst(request, true, true); if (!validate.Key) { response.ErrorCode = validate.Value; valid = false; } break; default: break; } if (valid) { process(response); } } catch (Exception ex) { Exception exception = ex; string message = string.Empty; do { message += exception.Message + "\t"; exception = ex.InnerException; } while (exception != null); response.DeveloperMessage = message; response.ErrorCode = ErrorCode.GeneralError; Logger.Exception(ex); } return(response); }
protected JsonResult RentoJsonDelete(RentoResponse response, string actionUrl) { return(RentoJsonObject(new { Message = response.Message, ErrorCode = response.ErrorCode, ActionUrl = actionUrl })); }
protected JsonResult RentoJson(RentoResponse response, JsonRequestBehavior behavior = JsonRequestBehavior.AllowGet) { return(RentoJsonObject(response, behavior)); }
public IHttpActionResult SignUp(RentoRequest <Customer> request) { var userId = 0; var welcomeFilePath = string.Empty; var response = new RentoResponse <string>(request); return(Ok(TryCatch(request, response, ValidateType.None, async() => { var hasIdentifier = request.Data.Identifier != null && string.IsNullOrEmpty(request.Data.Identifier.Content); var hasLicence = request.Data.Identifier != null && string.IsNullOrEmpty(request.Data.Licence.Content); var identefier = string.Empty; var licence = string.Empty; if (hasIdentifier) { identefier = request.Data.Identifier.Content; request.Data.Identifier.Content = "Base64 string"; } if (hasLicence) { licence = request.Data.Licence.Content; request.Data.Licence.Content = "Base64 string"; } Logger.Debug("SignUp", request.Data); if (hasLicence) { request.Data.Licence.Content = licence; if (!FileExtension.ScanImage(request.Data.Licence.ContentArray)) { response.ErrorCode = ErrorCode.InvalidImageFormat; return; } } if (hasIdentifier) { request.Data.Identifier.Content = identefier; if (!FileExtension.ScanImage(request.Data.Identifier.ContentArray)) { response.ErrorCode = ErrorCode.InvalidImageFormat; return; } } if (!string.IsNullOrEmpty(request.Data.BirthDate)) { request.Data.DOP = DateTime.ParseExact(request.Data.BirthDate, "dd/MM/yyyy", null); } if (ValidateRequirdField(request.Data.IdentifierId) && ValidateRequirdField(request.Data.DOP) ) { request.Data.Flag = (int)CustomerFlag.CompleteBySignUp; } else { request.Data.Flag = (int)CustomerFlag.UnComplete; } if (!ValidateRequirdField(request.Data.Mobile, request.Data.Password, request.Data.Username, request.Data.Email, request.Data.FullName)) { response.ErrorCode = ErrorCode.RequirdField; return; } request.Data.Mobile = SMSMessage.CheckMobileNumber(request.Data.Mobile); userId = await AccountManager.SignUp(request.Data); if (userId == 0) { response.ErrorCode = ErrorCode.UsernameAlreadyExists; return; } RunActionAsync(() => { var imagePath = HostingEnvironment.MapPath("~/App_Data"); var fileId = ImageHelper.WriteOnImage(imagePath + "/welcome.jpeg", request.Data.FullName, imagePath); welcomeFilePath = Path.Combine(imagePath, fileId); LinkedResource LinkedImage = new LinkedResource(welcomeFilePath); LinkedImage.ContentId = "ERent"; LinkedImage.ContentType = new ContentType(MediaTypeNames.Image.Jpeg); AlternateView htmlView = AlternateView.CreateAlternateViewFromString("<img src=cid:ERent>", null, "text/html"); htmlView.LinkedResources.Add(LinkedImage); EmailMessage.SendEmail("*****@*****.**", request.Data.Email, request.Language == (int)Language.Arabic ? "مرحبا بك في " + "E-Rent" : "Welcome to E-Rent", " ", null, htmlView); if (!string.IsNullOrEmpty(welcomeFilePath) && File.Exists(welcomeFilePath)) { File.Delete(welcomeFilePath); } }); string token = GenerateToken(request.Data.Username, userId, (int)UserType.Customer_Pending); SendVirificationCode(request.Data.Mobile, userId, token); response.Data = token; }))); }
public IHttpActionResult UpdateUserInfo(RentoRequest <User> request) { var response = new RentoResponse(request); return(Ok(TryCatch(request, response, ValidateType.Pending, async() => { var licence = request.Data.Licence; var logo = request.Data.Logo; var refarmeCard = request.Data.RefarmeCard; if (request.Data.Licence != null) { if (!Rento.Helper.FileExtension.ScanImage(request.Data.Licence.Content)) { response.ErrorCode = ErrorCode.InvalidImageFormat; return; } request.Data.Licence = new RentoImage(); } if (request.Data.Logo != null) { if (!Rento.Helper.FileExtension.ScanImage(request.Data.Logo.Content)) { response.ErrorCode = ErrorCode.InvalidImageFormat; return; } request.Data.Logo = new RentoImage(); } if (request.Data.RefarmeCard != null) { if (!Rento.Helper.FileExtension.ScanImage(request.Data.RefarmeCard.Content)) { response.ErrorCode = ErrorCode.InvalidImageFormat; return; } request.Data.RefarmeCard = new RentoImage(); } Logger.Debug("User - UpdateUserInfo", request); request.Data.Licence = licence; request.Data.Logo = logo; request.Data.RefarmeCard = refarmeCard; if (!ValidateRequirdField(request.Data.CityId, request.Data.CountryId) || ((UserType)UserSession.Type == UserType.Pending && (request.Data.Licence == null || request.Data.RefarmeCard == null)) || !ValidateRequirdField(request.Data.Mobile, request.Data.Name) || !ValidateRequirdField(request.Data.Latitude, request.Data.Latitude) ) { response.ErrorCode = ErrorCode.RequirdField; return; } request.Data.Mobile = SMSMessage.CheckMobileNumber(request.Data.Mobile); request.Data.Id = UserSession.Id; await Database.AccountManager.Update(request.Data); if ((UserType)UserSession.Type == UserType.Pending) { UserSession.Type = (int)UserType.Active; } RentoCache.Set(request.Data.Id.ToString(), (byte)UserSession.Type); }))); }