public async Task <JsonResult> GetEmployeeOwners([FromHeader] string Authorization) { string token = Authorization.Split(' ')[1]; var user = (from bb in _context.Auths join aa in _context.Tokens on bb.id equals aa.user_id join cc in _context.Accounts on bb.id equals cc.id_user where aa.access == token select cc).FirstOrDefault(); var staffs = await _context.EmployeeOwners.Where(x => x.id_owner == user.id).ToListAsync(); List <SendEmployee> send = new List <SendEmployee>(); foreach (var a in staffs) { var b = new SendEmployee(a); var auth = await _context.Auths.FindAsync(a.id_user); b.lastvisit = auth.last_visit; b.role = auth.role; send.Add(b); } return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.OK, send, null))); }
public async Task <JsonResult> GetAccount(int id, string returnUrl = null) { var account = await _context.Accounts.FindAsync(id); if (account == null) { return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.NotFound, null, "Пользователь не найден"))); } var send = await _account.GetData(account); return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.OK, send, null))); }
public async Task <JsonResult> GetCoordinateNear([FromBody] AccountGeo coordinate) { var coor = (from aa in _context.EmployeeOwners join bb in _context.Accounts on aa.id_owner equals bb.id join ee in _context.Coordinates on aa.id_owner equals ee.account_id join cc in _context.Services on aa.id equals cc.account_id where cc.category == coordinate.category_id select new AccountGeoSend { lat = ee.lat, lng = ee.lon, name = bb.name, price = cc.price }).Distinct().ToList(); foreach (var a in coor) { double res = Math.Pow((a.lat - coordinate.lat), 2) + Math.Pow((a.lng - coordinate.lng), 2); a.distinct = Math.Sqrt(res); } return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.OK, coor, null))); }
public async Task <JsonResult> GetServices([FromHeader] string Authorization) { string token = Authorization.Split(' ')[1]; var user = (from bb in _context.Auths join aa in _context.Tokens on bb.id equals aa.user_id join cc in _context.EmployeeOwners on bb.id equals cc.id_user where aa.access == token select new { id = cc.id, role = bb.role, account_id = cc.id }).FirstOrDefault(); if (user == null) { return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.NotFound, null, "Пользователь не найден"))); } var services = (from aa in _context.Services join bb in _context.Categories on aa.category equals bb.id where aa.account_id == user.account_id select new SendServices { descride = aa.descride, subcategory = bb.name, minutes = aa.minutes, name = aa.name, price = aa.price, parent = bb.parent, id = aa.id }).ToList(); foreach (var a in services) { a.category = _context.Categories.Find(a.parent).name; } return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.OK, services, null))); }
public async Task <JsonResult> GetClients([FromQuery] Category category) { var r = (from aa in _context.EmployeeOwners join bb in _context.Services on aa.id equals bb.account_id join cc in _context.Accounts on aa.id_owner equals cc.id join ee in _context.categoryAccounts on aa.id_owner equals ee.id_account where bb.category == category.id select new Company { desc = cc.address, category = ee.level1, name = cc.name, }).ToList(); foreach (var a in r) { var avatar = await _context.Userpics.Where(x => x.account_id == a.account_id).FirstOrDefaultAsync(); if (avatar != null) { using (Image image = Image.FromFile(avatar.path)) { using (MemoryStream m = new MemoryStream()) { image.Save(m, image.RawFormat); byte[] imageBytes = m.ToArray(); // Convert byte[] to Base64 String a.avatar = Convert.ToBase64String(imageBytes); } } } } return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.OK, r, null))); }
public async Task <JsonResult> Get([FromQuery] string month, [FromQuery] string year, [FromHeader] string Authorization) { string token = Authorization.Split(' ')[1]; var user = (from bb in _context.Auths join dd in _context.Tokens on bb.id equals dd.user_id where dd.access == token select bb).FirstOrDefault(); if (user == null) { return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.NotFound, null, "Пользователь не найден"))); } else if (user.role == "staff") { try { var staff = await _context.EmployeeOwners.Where(x => x.id_user == user.id).FirstOrDefaultAsync(); string s = String.Format("01/{0}/{1}", month, year); var start = DateTime.Parse(s); var end = start.AddMonths(1); var days = await _context.dayOfWorks.Where(x => x.dttmStart > start && x.dttmEnd < end && x.accountId == staff.id).ToListAsync(); return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.OK, days, null))); } catch (Exception ex) { return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.BadRequest, null, ex.Message))); } } else { List <SendCalendar> send = new List <SendCalendar>(); var staff = await _context.EmployeeOwners.Where(x => x.id_owner == user.id).ToListAsync(); string s = String.Format("01/{0}/{1}", month, year); var start = DateTime.Parse(s); var end = start.AddMonths(1); foreach (var a in staff) { var days = await _context.dayOfWorks.Where(x => x.dttmStart > start && x.dttmEnd < end && x.accountId == a.id).ToListAsync(); var temp = new SendCalendar { days = new List <string>(), id_staff = a.id }; foreach (var b in days) { temp.days.Add(b.dttmStart.ToString("yyyy-MM-dd").Split(' ')[0]); } send.Add(temp); } return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.OK, send, null))); } return(null); }
public async Task <JsonResult> Change_Password([FromBody] Password email) { var auth = await _context.Auths.Where(x => x.email == email.email).FirstOrDefaultAsync(); if (auth == null) { return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.NotFound, null, "Пользователь с таким email Не найден"))); } bool result = await _auth.ChangePassword(auth); if (result) { return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.OK, null, "Пароль сгенерирован"))); } return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.BadRequest, null, "Ошибка"))); }