Example #1
0
        public IHttpActionResult PostUserActions(AuditDTO model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (audittrail.validAppID(model.application_id))
                    {
                        if (audittrail.GetAppType(model.application_id) == "web")
                        {
                            audit_trail audit = new audit_trail()
                            {
                                id             = Guid.NewGuid(),
                                application_id = model.application_id,
                                user_id        = model.user_id,
                                action         = model.action,
                                date_time      = DateTime.Now,
                                device_name    = model.device_name,
                                os_version     = model.os_version,
                                location       = model.location,
                                ip_address     = model.ip_address
                            };

                            db.audit_trail.Add(audit);
                            db.SaveChanges();

                            if (db.SaveChanges() >= 0)
                            {
                                return(Ok());
                            }
                            else
                            {
                                return(Conflict());
                            }
                        }
                        else if (audittrail.GetAppType(model.application_id) == "ios")
                        {
                            audit_trail audit = new audit_trail()
                            {
                                id             = Guid.NewGuid(),
                                application_id = model.application_id,
                                user_id        = model.user_id,
                                action         = model.action,
                                date_time      = DateTime.Now,
                                device_name    = model.device_name,
                                os_version     = model.os_version,
                                location       = model.location,
                                ip_address     = null
                            };

                            db.audit_trail.Add(audit);
                            db.SaveChanges();

                            if (db.SaveChanges() >= 0)
                            {
                                return(Ok());
                            }
                            else
                            {
                                return(Conflict());
                            }
                        }
                        else
                        {
                            return(NotFound());
                        }
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
                return(BadRequest(ModelState));
            }
            catch (Exception e)
            {
                return(InternalServerError(e));
            }
        }