public IHttpActionResult UploadFile() { int userId = GetUserId(); if (userId == 0) { reqResponse.ErrorMessages.Add("noUser", "Invalid Data"); return(Ok(reqResponse)); } string fileName = RandomNumber(20) + ".jpg"; var file = HttpContext.Current.Request.Files.Count > 0 ? HttpContext.Current.Request.Files[0] : null; if (file != null && file.ContentLength > 0) { // var fileName = Path.GetFileName(file.FileName); var path = Path.Combine( HostingEnvironment.MapPath("~/DataImages/"), // HttpContext.Current.Server.MapPath("~/DataImages"), fileName ); file.SaveAs(path); using (SecurityUserRepository secUserRepo = new SecurityUserRepository()) { var curentModel = secUserRepo.GetById(userId); curentModel.IdString = fileName; secUserRepo.AddUpdate(curentModel); } } return(Ok(reqResponse)); //return file != null ? "/uploads/" + file.FileName : null; }
public IHttpActionResult Subscription(SubscriptionModel data) { int userId = GetUserId(); if (userId == 0) { reqResponse.ErrorMessages.Add("noUser", "Invalid Data"); return(Ok(reqResponse)); } using (SecurityUserRepository secUserRepo = new SecurityUserRepository()) { var currentUser = secUserRepo.GetById(userId); //data.Name = "ddd"; //data.PhoneNumber = 2525; data.Name = currentUser.FullName; data.PhoneNumber = int.Parse(currentUser.Telephone); } data.riderId = userId; if (string.IsNullOrEmpty(data.Name) || string.IsNullOrEmpty(data.PhoneNumber.ToString()) || data.PhoneNumber <= 0 || string.IsNullOrEmpty(data.Location) || string.IsNullOrEmpty(data.DateTimeStr)) { reqResponse.ErrorMessages.Add("invalidD", "Invalid Data"); return(Ok(reqResponse)); } data.DateTimeStr = data.DateTimeStr;// + " " + data.TimeStr; if (!string.IsNullOrEmpty(data.PromoCodeName)) { using (PromoCodeRepository promoRepo = new PromoCodeRepository()) { DomainModel.PromoCode promoCode = promoRepo.GetByName(data.PromoCodeName); if (promoCode != null) { if (promoCode.IsDeleted != true) { data.PromoCodeId = promoCode.Id; } } // return Ok(reqResponse); } } DateTime tempDate = new DateTime(); try { tempDate = DateTime.ParseExact(data.DateTimeStr, "dd/MM/yyyy hh:mm tt", CultureInfo.InvariantCulture); } catch (Exception) { tempDate = DateTime.ParseExact(data.DateTimeStr, "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture); } //DateTime ddd = DateTime.ParseExact(data.DateTimeStr,"dd/MM/yyyy hh:mm tt", CultureInfo.InvariantCulture); using (SubscriptionRepository subscriptionRepo = new SubscriptionRepository()) { return(Ok( subscriptionRepo.AddUpdate(new DomainModel.SubscriptionV() { Name = data.Name, PhoneNumber = data.PhoneNumber, LocationStr = data.Location, Lat = data.Lat, Lng = data.Lng, PickDateTime = tempDate, DaysCount = data.DaysCount, PromoCodeId = data.PromoCodeId, UserId = data.riderId, PayMobId = data.PayMobId }) )); } }