Ejemplo n.º 1
0
 public async Task <IHttpActionResult> SaveNotificationToken()
 {
     try
     {
         var userId = User.Identity.GetUserId();
         if (userId != null)
         {
             using (MaxMasterDbEntities db = new MaxMasterDbEntities())
             {
                 var employee = db.Employees.Where(x => x.AspNetUserId == userId).FirstOrDefault();
                 if (employee != null)
                 {
                     employee.NotificationToken = HttpContext.Current.Request.Form.Get("Token");
                     db.Entry(employee).State   = System.Data.Entity.EntityState.Modified;
                     await db.SaveChangesAsync();
                 }
             }
         }
         return(Ok());
     }
     catch (Exception ex)
     {
         new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace);
         return(Content(HttpStatusCode.InternalServerError, "An error occoured, please try again!"));
     }
 }
Ejemplo n.º 2
0
 public async Task <IHttpActionResult> PopulateEmptyAddresses()
 {
     try
     {
         using (MaxMasterDbEntities db = new MaxMasterDbEntities())
         {
             var emptyAddressLocations = db.EmployeeAttendanceLogs.Where(x => x.Address == null).ToList();
             foreach (var location in emptyAddressLocations)
             {
                 try
                 {
                     string      latlon = location.Latitude + "," + location.Longitude;
                     XmlDocument xDoc   = new XmlDocument();
                     xDoc.Load("https://maps.googleapis.com/maps/api/geocode/xml?latlng=" + latlon + "&key=AIzaSyCPbyemMRyuWmR7yiD-nIwXaaeZaw-jK9o");
                     XmlNodeList xNodelst = xDoc.GetElementsByTagName("result");
                     XmlNode     xNode    = xNodelst.Item(0);
                     location.Address         = xNode.SelectSingleNode("formatted_address").InnerText;
                     db.Entry(location).State = System.Data.Entity.EntityState.Modified;
                     await db.SaveChangesAsync();
                 }
                 catch
                 {
                 }
             }
         }
         return(Content(HttpStatusCode.OK, "Success"));
     }
     catch (Exception ex)
     {
         new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace);
         return(Content(HttpStatusCode.InternalServerError, "An error occured, please try again later"));
     }
 }
        protected override async Task <HttpResponseMessage> SendAsync(
            HttpRequestMessage request, CancellationToken cancellationToken)
        {
            var result = await base.SendAsync(request, cancellationToken);

            var context = ((HttpContextBase)request.Properties["MS_HttpContext"]);
            var userId  = context.User.Identity.GetUserId();

            if (userId != null)
            {
                using (MaxMasterDbEntities db = new MaxMasterDbEntities())
                {
                    var employee = db.Employees.Where(x => x.AspNetUserId == userId).FirstOrDefault();
                    if (employee != null)
                    {
                        employee.LastActivityTime = DateTime.Now;
                        db.Entry(employee).State  = System.Data.Entity.EntityState.Modified;
                        db.SaveChangesAsync();
                    }
                }
            }

            return(result);
        }