public async Task <JsonResult> register(string username, string password, string email, string firstName, string lastName, int gender, DateTime birthday, string telephone, string address, int imageId = 0, IFormFile image_file = null) { long lTime = new DateTimeOffset(Convert.ToDateTime(DateTime.Now)).ToUniversalTime().ToUnixTimeSeconds(); VMError objError = new VMError(); if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(telephone) || string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName)) { objError.code = 201; objError.message = "Data không hợp lệ"; return(await Task.Run(() => Json(new { result = 0, time = lTime, data = new { userId = 0, access_token = "" }, error = objError }))); } int addressId = 0; int telephoneId = 0; int collectionId = 0; if (!string.IsNullOrEmpty(address)) { addressId = await new B_Address().Create(address); } if (!string.IsNullOrEmpty(telephone)) { telephoneId = await new B_TelePhone().Create(telephone); } var collection = await new B_Collection().ReadByName("nguoi_dung"); if (collection != null) { collectionId = collection.Id; if (image_file != null) { var imgHelper = new B_Image(); imageId = await imgHelper.UploaImg(image_file, "https://admin.kingattorney.net", "AppMobile"); } var helper = new B_Account(); var dataItem = await helper.Create(username, password, email, "nguoi_dung", "", firstName, lastName, gender, birthday, imageId, addressId, telephoneId, 0, collectionId); objError.message = dataItem["msg"]; if (dataItem["result"] == "1") { return(await Task.Run(() => Json(new { result = 1, time = lTime, data = new { userId = Convert.ToInt32(dataItem["userid"]), access_token = dataItem["access_token"] }, error = objError }))); } } objError.code = 201; objError.message = "Đăng ký không thành công"; return(await Task.Run(() => Json(new { result = 0, time = lTime, data = new { userId = 0, access_token = "" }, error = objError }))); }
public async Task <List <VMInfoNews> > GetNews(string keyword, int numberRecords) { if (string.IsNullOrEmpty(keyword)) { return(new List <VMInfoNews>()); } var collectionHelper = new B_Collection(); var collection = await collectionHelper.ReadByName(keyword); if (collection == null) { return(new List <VMInfoNews>()); } var contentHelper = new B_Content(); var contents = await contentHelper.Reads(collection.Id, 1); if (contents == null || !contents.Any()) { return(new List <VMInfoNews>()); } var imageHelper = new B_Image(); var Images = await imageHelper.ReadByIds(contents.Select(s => s.ImageId).ToList()); var dataItems = contents.Join(Images, a => a.ImageId, b => b.Id, (a, b) => new { a, b }) .Select(s => new VMInfoNews() { id = s.a.Id, image_url = s.b.RelativeUrl + "/" + s.b.Name, name = s.a.Title, description = s.a.Description, content = s.a.Text, date = s.a.CreatedAt.Date.ToString("dd/MM/yyyy"), }) .Take(numberRecords) .ToList(); if (dataItems == null || !dataItems.Any()) { return(new List <VMInfoNews>()); } return(dataItems); }
public async Task <JsonResult> Edit(string access_token, string first_name, string last_name, string email, string telephone, DateTime dob, string address_text, int gender, int status, int imageId = 0, IFormFile image_file = null) { long lTime = new DateTimeOffset(Convert.ToDateTime(DateTime.Now)).ToUniversalTime().ToUnixTimeSeconds(); if (string.IsNullOrEmpty(access_token) || string.IsNullOrEmpty(first_name) || string.IsNullOrEmpty(last_name) || string.IsNullOrEmpty(telephone) || string.IsNullOrEmpty(email)) { return(await Task.Run(() => Json(new { result = 0, time = lTime, data = 0, error = "Dữ liệu không hợp lệ" }))); } var user = TokenProvider.DecodeToken(access_token); if (user == null) { return(await Task.Run(() => Json(new { result = 0, time = lTime, data = 0, error = "Access Token không hợp lệ" }))); } int addressId = 0; int collectionId = 0; int telephoneId = 0; var helper = new B_Account(); var item = helper.ReadAccount(user.user.id); if (item == null) { return(await Task.Run(() => Json(new { result = 0, time = lTime, data = new object(), error = "User không tồn tại" }))); } if (item.email != email) { if (!VIConvert.IsValidEmail(email)) { return(await Task.Run(() => Json(new { result = 0, time = lTime, data = new object(), error = "Email không hợp lệ " }))); } if (helper.IsExistEmail(email)) { return(await Task.Run(() => Json(new { result = 0, time = lTime, data = new object(), error = "Email đã tồn tại" }))); } } if (item.phone_id == 0) { var telHelper = new B_TelePhone(); if (telHelper.isExist(telephone)) { return(await Task.Run(() => Json(new { result = 0, time = lTime, data = new object(), error = "Số điện thoại đã tồn tại" }))); } telephoneId = await telHelper.Create(telephone); } else { if (item.phone != telephone) { var telHelper = new B_TelePhone(); if (telHelper.isExist(telephone)) { return(await Task.Run(() => Json(new { result = 0, time = lTime, data = new object(), error = "Số điện thoại đã tồn tại" }))); } var result = await telHelper.Update(item.phone_id, telephone); } telephoneId = item.phone_id; } var addHelper = new B_Address(); if (item.address_id == 0) { addressId = await addHelper.Create(address_text); } else { await addHelper.Update(item.address_id, address_text); addressId = item.address_id; } var colHelepr = new B_Collection(); var collectionItem = await colHelepr.ReadByName("nguoi_dung"); if (collectionItem != null) { collectionId = collectionItem.Id; } if (item.img_id != 0) { if (image_file != null) { var imgHelper = new B_Image(); await imgHelper.UpdateImg(image_file, "https://admin.kingattorney.net", item.img_id, "AppMobile"); imageId = item.img_id; } } else { if (image_file != null) { var imgHelper = new B_Image(); imageId = await imgHelper.UploaImg(image_file, "https://admin.kingattorney.net", "AppMobile"); } } var dataItems = await helper.Update(user.user.id, email, "nguoi_dung", "", first_name, last_name, gender, dob, imageId, addressId, telephoneId, 0, collectionId, status, 0, "", "", "", "", ""); if (dataItems["result"] == "1") { return(await Task.Run(() => Json(new { result = 1, time = lTime, data = dataItems, error = "" }))); } return(await Task.Run(() => Json(new { result = 0, time = lTime, data = new object(), error = dataItems["msg"] }))); }
public async Task <List <VMPartner> > getPartner(string keyword, int status) { if (string.IsNullOrEmpty(keyword)) { return(new List <VMPartner>()); } var collectionHelper = new B_Collection(); var collection = await collectionHelper.ReadByName(keyword); if (collection == null) { return(new List <VMPartner>()); } var helper = new B_Account(); var items = await helper.ReadByCollectionId(collection.Id, status); if (items == null || !items.Any()) { return(new List <VMPartner>()); } var imgHelper = new B_Image(); var imgs = await imgHelper.ReadByIds(items.Select(s => s.AvatarId).ToList()); var telHelper = new B_TelePhone(); var tels = await telHelper.ReadByIds(items.Select(s => s.TelePhoneId).ToList()); var addHelper = new B_Address(); var address = await addHelper.ReadByIds(items.Select(s => s.AddressId).ToList()); var contentHelper = new B_Content(); var contents = await contentHelper.ReadByIds(items.Select(s => s.contentId).ToList()); using (var db = new KingAttornyContext()) { try { var dataItem = items .Select(s => new VMPartner() { id = s.Id, name = s.FirstName + " " + s.LastName, avatar_id = s.AvatarId, business = s.BusinessNamne, content_id = s.contentId, google_plus_url = s.GooplePlusUrl, facebook_fanpage_url = s.FacebookFanpageUrl, twitter_fanpage_url = s.TwitterFanpageUrl, zalo = s.Zalo, address_id = s.AddressId, telephone_id = s.TelePhoneId }) .ToList(); if (dataItem != null && dataItem.Any()) { foreach (var i in dataItem) { var itemAdd = address.Where(s => s.Id == i.address_id).FirstOrDefault(); if (itemAdd != null) { i.address = itemAdd.AddressText; } var itemTele = tels.Where(s => s.Id == i.telephone_id).FirstOrDefault(); if (itemTele != null) { i.telephone = itemTele.PhoneNumber; } var itemImg = imgs.Where(s => s.Id == i.avatar_id).FirstOrDefault(); if (itemImg != null) { i.avatar_url = itemImg.RelativeUrl + "/" + itemImg.Name; } var itemContents = contents.Where(s => s.Id == i.content_id).FirstOrDefault(); if (itemContents != null) { i.content_detail = itemContents.Text; i.description = itemContents.Description; } } } return(dataItem); } catch (Exception ex) { return(new List <VMPartner>()); } } }